word-vba

With a Word ContentControl DatePicker how do i get the value?

泄露秘密 提交于 2019-11-28 09:05:25
问题 I have a ContentControl that is a DatePicker in a word document. I'm trying to use it to populate some value in a code behind but I cant seem to get the value out of it. Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, _ Cancel As Boolean) None of the properties on ContentControl are close to .Value or .Text. I have seen other content controls use: ContentControl.DropdownListEntries(1).Text ContentControl.DropdownListEntries(1).Value This, as expected for a

A good substitute for references/pointers in VBA?

◇◆丶佛笑我妖孽 提交于 2019-11-28 08:13:09
问题 Can you recommend me a good substitute for reference or pointer types in VBA? I have been struggling for long with expressions like this: dblMyArray( i * lngDimension0 + j * lngDimension1 + k * lngDimension2, l * lngDimension3 + m * lngDimension4 ) = dblMyArray( i * lngDimension0 + j * lngDimension1 + k * lngDimension2, l * lngDimension3 + m * lngDimension4 ) + 1 If I wanted to accumulate values in a multidimensional array in e.g. C++, I could write this: double& rElement = dblMyArray[ i *

“Run-time error 462 : The remote server machine does not exist or is unavailable” when running VBA code a second time

不羁的心 提交于 2019-11-28 07:46:20
问题 The code below is working fine the first time I run it, but when I need to run it a second time , it gives me this error: Run Time error '462': the remote server machine does not exist or is unavailable It doesn't happen all the time so I suppose it has something to do with Word (not) running in the background...? What am I missing here? Sub Docs() Sheets("examplesheet").Select Dim WordApp1 As Object Dim WordDoc1 As Object Set WordApp1 = CreateObject("Word.Application") WordApp1.Visible =

Workarounds for gaps in Word for Mac 2011 VBA object model?

帅比萌擦擦* 提交于 2019-11-28 06:28:40
问题 There seem to be a bunch of things in the Word 2007/2010 VBA object model which are simply missing in Word 2011 VBA. Specifically, Word 2007 (for Windows) includes objects and methods related to: ContentControls CustomXMLParts OpenXML For example: **Word.Document** Property ContentControls As ContentControls contentcontrol events eg Event ContentControlAfterAdd(NewContentControl As ContentControl, InUndoRedo As Boolean) Property CustomXMLParts As CustomXMLParts Property WordOpenXML As String

Word VBA - DocumentBeforeSave event?

这一生的挚爱 提交于 2019-11-28 06:11:52
问题 I am using the following VBA code to make a message box appear while saving the Word document, Public WithEvents appWord as Word.Application Private Sub appWord_DocumentBeforeSave _ (ByVal Doc As Document, _ SaveAsUI As Boolean, _ Cancel As Boolean) Dim intResponse As Integer intResponse = MsgBox("Do you really want to " _ & "save the document?", _ vbYesNo) If intResponse = vbNo Then Cancel = True End Sub This code was written in a Class. But this does not work. Nothing happens when saving.

Why do I not see the Microsoft Forms 2.0 Object Library?

丶灬走出姿态 提交于 2019-11-28 03:35:31
问题 I would like to use this library to work with the clipboard. I expect to see it as in the screenshot below, but I can't find it in my list of reference libraries. How can I make it appear? 回答1: If you add a UserForm to your project, the library will get automatically added. If you don't need the UserForm, you can always delete it later. 来源: https://stackoverflow.com/questions/35610429/why-do-i-not-see-the-microsoft-forms-2-0-object-library

Restrict/Lock bookmarks from editing in word

青春壹個敷衍的年華 提交于 2019-11-28 03:09:31
问题 I have many word document with lots of bookmarks. I use VBA code to change these bookmarks with data from a DB. The problem is, sometimes the users need to edit these documents, and they tend to accidentally delete/change my bookmarks, which leads to the VBA code not recognizing the bookmark anymore. So basically, what i'm wondering is how i can restrict users from editing my bookmarks in a word document. I don't need a super secure solution, just enough protection so that the user knows that

How to loop through each word in a word document - VBA Macro

拥有回忆 提交于 2019-11-28 01:56:19
问题 I know how to get every paragraph in a word document. But I am looking for a way to loop through each word in a MS Word document. Sub Sample() Dim apara As Paragraph Dim lineText As String For Each apara In ActiveDocument.Paragraphs lineText = apara.Range 'Now print the paragraph Debug.Print lineText Next apara End Sub 回答1: For Each sentence In ActiveDocument.StoryRanges For Each w In sentence.Words Debug.Print w Next Next 回答2: Here's another, very similar solution which may be helpful for

Copy RTF text from Access to word table using VBA

时光毁灭记忆、已成空白 提交于 2019-11-28 01:20:23
问题 Is there a way to copy a RTF text from a memo field in Access Database to Word document using VBA. I have this code at the moment but it produces html text (the text includes tags and not formatted). ' Query the database and get the sales for the specified customer Set rs = CurrentDb.OpenRecordset("SELECT * FROM Sales WHERE Sales.[ID] ='" & Forms![customers]![id] & "'") 'Check to see if the recordset actually contains rows If Not (rs.EOF And rs.BOF) Then rs.MoveFirst Do Until rs.EOF = True '

How to check if clipboard is empty of text?

核能气质少年 提交于 2019-11-27 22:37:57
问题 If I try to paste from an empty clipboard, I get an error. I would like to check if the clipboard is empty of text before pasting so that I can avoid this. How can this be accomplished? I'm aware it can be done through error handling, but I would prefer a method that avoids an error. Edit -- Per request, adding code that creates the error and the error message: Code that causes the problem: Sub PasteFromEmptyClipBoard() Selection.Paste End Sub Error message that I get: "Run-time error '4605'