word-vba

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

大兔子大兔子 提交于 2019-11-29 12:30:32
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.ContentControl** Property XMLMapping As XMLMapping **Word.ContentControls** Function Add([Type

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

a 夏天 提交于 2019-11-29 10:21:27
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? 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

Microsoft Word Macro for highlighting multiple words

只愿长相守 提交于 2019-11-29 09:42:54
问题 My intent is to create a very basic macro to find a series of words and highlight them. Unfortunately, I do not know how to do multiple words in one step. For example, the following code works: Sub Macro1() ' ' Macro1 Macro ' ' Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting Selection.Find.Replacement.Highlight = True With Selection.Find .Text = "MJ:" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = True .MatchWholeWord =

Restrict/Lock bookmarks from editing in word

最后都变了- 提交于 2019-11-29 09:23:37
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, "i should not touch this part". Thanks in advance for your answer.. EDIT: I was reading on different

Linked Table in MS Word

不问归期 提交于 2019-11-29 08:39:26
I would like to refresh Excel tables in a Word template report programmatically using VBA. The tables are written to several sheets in a template Excel file from Matlab. The file structure will look like this: The code would have to check the folder structure to see if it is pulling the Excel file out of the newest folder. If it was, it would just refresh all of the cells. If not, it would have to delete all of the tables and insert new ones from the same sheets as the previous ones were pulled. I am unsure of the code between the asterisks below. Any help would be much appreciated. Sub

Word VBA and Multiple Word Instances

亡梦爱人 提交于 2019-11-29 08:32:13
Good morning. I am having a problem with getting my code to find other instances of word and have hit a brick wall after much google searching. My Code below will find all open word documents and populate them into a combo box. My problem is we have applications (I have no control over these) that will open word documents in a new instance and therefore my code will not find/control these documents. Any ideas? Dim objWordDocument As Word.Document Dim objWordApplication As Word.Application '//find all open word documents Set objWordApplication = GetObject(, "Word.Application") '//clear combobox

How to run a macro in Word before save?

瘦欲@ 提交于 2019-11-29 07:59:32
How to make Microsoft Word to run a VBA macro every time before any document is saved? Could it be done without adding macros into the document itself? You can subscribe to application events in Document_Open by using WithEvents variable and conventional method names ( VariableName_EventName ). Works in templates as well. You can put this code into ThisDocument object, or make a separate class module as described here . Private WithEvents App As Word.Application Private Sub Document_Open() Set App = Word.Application End Sub Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As

How to check if clipboard is empty of text?

独自空忆成欢 提交于 2019-11-29 07:54:21
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' This method or property is not available because the Clipboard is empty or is not valid." Very

Using vba to copy the contents of a word document into another word document

旧巷老猫 提交于 2019-11-29 07:31:59
I haven't used VB for years, so please forgive me if this turns out to be obvious. I'm trying to write a word vba macro for use in a template which will display a userform and then import the contents of fileA.docx, fileB.docx, or fileC.docx depending on the userform. (After that I'm going to use bookmarks to fill in some form data, I don't know if that's relevant). Files A, B, and C will contain text with some basic formatting such as lists, but nothing fancy. The solutions I've seen online can copy the contents of file to a new file, but ideally I would like to import the entirety of one of

How to get the email address of the current logged-in user?

大城市里の小女人 提交于 2019-11-29 07:14:13
I'm new to VBA and trying to get an automated word document working. At the moment there is a Button in the document that which upon pressing, will fire off an email with the document attached. However I need to also get the email address of the current user sending the email, so I can place it inside the document before sending it off. My searches on the internet have not resulted in any usable code that meets my situation. My current code is below. Set OL = CreateObject("Outlook.Application") Set EmailItem = OL.CreateItem(olMailItem) Set Doc = ActiveDocument Doc.Save With EmailItem .Subject