word-vba

How to programmatically edit all hyperlinks in a Word document?

孤街醉人 提交于 2019-11-30 12:34:22
Is there a macro, VBA code or VBScript that I can write to edit the urls of all the hyperlinks in my Word document? Either Word 97-2003 or docx format. Dim doc As Document Dim link, i 'Loop through all open documents. For Each doc In Application.Documents 'Loop through all hyperlinks. For i = 1 To doc.Hyperlinks.Count 'If the hyperlink matches. If LCase(doc.Hyperlinks(i).Address) = "http://www.yahoo.com/" Then 'Change the links address. doc.Hyperlinks(i).Address = "http://www.google.com/" 'Change the links display text if desired. doc.Hyperlinks(i).TextToDisplay = "Changed to Google" End If

Using base64 data stored in CustomXMLPart as image in Office

旧街凉风 提交于 2019-11-30 10:47:36
As a followup to this question about using images stored in an Excel file on a button in the ribbon: Is it possible to use an image stored in a CustomXMLPart/CustomXMLNode in base64-encoded string as an image in an Office document without first saving it to disk and loading it back? The place where I want to use the image takes an IPictureDisp object as a parameter (like the LoadPicture function returns, but that will only load files from disk). First you need to convert your base_64 data to byte array: Private Function decodeBase64(ByVal strData As String) As Byte() Dim objXML As MSXML2

How can I reliably get the number of pages in a Word document?

我与影子孤独终老i 提交于 2019-11-30 08:54:53
I am making lots of changes to a Word document using automation, and then running a VBA macro which - among other things - checks that the document is no more than a certain number of pages. I'm using ActiveDocument.Information(wdNumberOfPagesInDocument) to get the number of pages, but this method is returning an incorrect result. I think this is because Word has not yet updated the pagination of the document to reflect the changes that I've made. ActiveDocument.ComputeStatistics(wdStatisticPages) also suffers from the same issue. I've tried sticking in a call to ActiveDocument.Repaginate ,

Word VBA and Multiple Word Instances

橙三吉。 提交于 2019-11-30 08:52:59
问题 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 '/

Microsoft Word Macro for highlighting multiple words

喜你入骨 提交于 2019-11-30 07:39:43
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 = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find

How To Deploy Word 2010 Macros To Others?

折月煮酒 提交于 2019-11-30 07:33:06
问题 I have a macro that I developed in Word 2010. How do I send this to others to use? 回答1: Save the document as .dotm (macro enabled template). Save it to %Appdata%/Microsoft/word/startup Close word. Now, it will be accessible to all other word documents. If not by default, then go to templates and tick the file saved above to deploy, create a simple script that copies the file to the appropriate folder. You can probably deploy via email 回答2: From the sublime to the ridiculous, here are four

What is a story?

随声附和 提交于 2019-11-30 04:51:10
问题 In MS Word VBA, what is the unit of measure "Story" and where does it fit into the hierarchy of units in a Word document? This reference only says that wdUnits.wdStory refers to "a story" which is not helpful. I couldn't find any other references that explain what I'm looking for. 回答1: This is actually a more complicated question than most would think. In a Microsoft Word blog post stories are defined as: "...distinct regions of content that make up a Word document and share properties and

Automated Word Template Creation With VBA

▼魔方 西西 提交于 2019-11-30 04:47:37
问题 I am creating a word document template and am at a bit of a crossroads. I would like to populate the document with figures created from MATLAB and Excel tables populated from MATLAB outputs. The figures are organized into folders and the Excel tables are organized in sheets in an Excel template as shown here: I have asked several previous questions here with respect to automatically updating these tables and figures and now have the code for this: Linked Table in MS Word Linked Images and

Highlight (not delete) repeat sentences or phrases in a word document

馋奶兔 提交于 2019-11-30 04:13:37
I am getting the impression that this is not possible in word but I figure if you are looking for any 3-4 words that come in the same sequence anywhere in a very long paper I could find duplicates of the same phrases. I copy and pasted a lot of documentation from past papers and was hoping to find a simple way to find any repeated information in this 40+ page document there is a lot of different formatting but I would be willing to temporarily get rid of formatting in order to find repeated information. To highlight all duplicate sentences, you can also use ActiveDocument.Sentences(i) . Here

Regex Microsoft Word without destroying document formatting

混江龙づ霸主 提交于 2019-11-29 22:37:42
问题 It's well known that word's find and replace "wildcards" features suffer some severe limitations. The following code implements true regex find and replace in a word document, and variations on it are found in other Stackoverflow and SuperUser questions. Sub RegEx_PlainText(Before As String, After As String) Dim regexp As Object Set regexp = CreateObject("vbscript.regexp") With regexp .Pattern = Before .IgnoreCase = True .Global = True 'could be any Range , .Range.Text , or selection object