word-vba

Display HTML page in Office 2003 or 2007 task pane via VBA

☆樱花仙子☆ 提交于 2019-12-13 02:51:55
问题 Is it possible to display an HTML page in an Office 2003 and/or 2007 task pane via VBA? Background: We have a complicated configuration file that our users maintain in Word (using a real editor is not an option for our audience). We would like to create several toolbar buttons that display a basic HTML page in a task pane as a form of online help for our users. The reason we want to use a task pane to display help (vs. an external browser or traditional help engine) is so that the help

Word vba document.readonly status incorrectly returns false

时光毁灭记忆、已成空白 提交于 2019-12-13 01:48:10
问题 I have an excel project that checks word documents for a changed modify date and, if changed, it opens that document and imports the text from the word form fields into excel. The routine in excel that opens and imports the word documents is as follows: Sub CopyFromWord(pFile as String,aFile as string) Dim wdApp As Object On Error Resume Next Set wdApp = GetObject(, "Word.Application") If Err.Number <> 0 Then Set wdApp = CreateObject("Word.Application") Else 'word is already running End If On

Passing 1 of 3 values to a Sub

大城市里の小女人 提交于 2019-12-12 21:56:42
问题 I want to update a single (1 of 3) variable in a Sub . The 3 variables have already been assigned, but I would like to update one of the variables. See script below for a simple example of passing string s between subs in different Macros In Macro1 Sub Sub1() Text1 = "First Text" Text2 = "Second Text" Text3 = "Third Text" Call Macro2.Sub2(Text1, Text2, Text3) End Sub In Macro2 Public PassedText1, PassedText2, PassedText3 As String Sub Sub2(ByVal r1 As String, ByVal r2 As String, ByVal r3 As

How Force replace macro apply on header also

浪尽此生 提交于 2019-12-12 21:07:42
问题 I want to find & replace a text in word document. I created a macro as bellow. Sub Macro1() ActiveDocument.Content.Find.Execute FindText:="#Text1", ReplaceWith:="acca", _ Replace:=wdReplaceAll End Sub It replaced all occurred but not in header/footer!! How forced to work on entire document include header/body/footer? 回答1: I've always used this VBA code to Find/Replace, and it will do Headers/Footers along with the body of the document: Dim myStoryRange As Range For Each myStoryRange In

Get ContentControl by title (or tag)

泪湿孤枕 提交于 2019-12-12 20:24:25
问题 Document.ContentControls collection doesn't support item retrieval by name, only by index. Can I still get a specific ContentControl by a user-defined identifier so as to keep code readable? (e.g. Content control titles - Ms Office Forums claims it's only possible to try them one by one.) 回答1: There are Document.SelectContentControlsByTitle() and Document.SelectContentControlsByTag() methods for this. Since neither property of a control is guaranteed to be unique, both return a

Word 2007 VBA: ActiveDocument.CustomXMLParts

喜欢而已 提交于 2019-12-12 20:02:04
问题 In this tutorial (and many others), there's an integer in the CustomXMLParts object collection Load method that I can't find an explanation for. The Word 2007 VBA Reference doesn't seem to list the Load method either: ''# Load CustomerData.xml file ActiveDocument.CustomXMLParts.Add ActiveDocument.CustomXMLParts(4).Load ("c:\CustomerData.xml") What does the 4 represent? 回答1: There are always three built-in CustomXMLParts in every .docx (created by Word 2007/2010 - not necessarily a .docx

Programmatically Update Linked Named Range of excel object in MS Word (2007)

假如想象 提交于 2019-12-12 19:19:46
问题 First question, excuse me if this has already been solved, but I've searched thoroughly and cannot find an answer: I have linked several named ranges into a word document. This word doc (and the related excel workbook with named ranges) is a template: it's for a coworker who will make many copies of these templates (of both the word doc and the excel workbook). I would like to include a command button in the word doc that, when clicked, will update the sources for the linked named ranges.

Word VBA: ShapeRange.Delete unexpected behavior

只谈情不闲聊 提交于 2019-12-12 16:18:01
问题 The Background This is closely related to the question ms word 2010 macro How to select all shapes on a specific page. But this concerns an unexpected result I'm getting from ShapeRange.Delete , when trying to code an answer for that question. The Question So, to set up the question. I'm able to change properties of the first and last shape on each page. However, when I replace the statement that changes the shape property ( shp.Range.ShapeRange.Line.Weight = 10 ) with a statement that

How to determine if document is a template?

一曲冷凌霜 提交于 2019-12-12 15:14:52
问题 I am trying to figure out if a document is a simple document (.doc, .docx, .docm) or a template (.dot, .dotx, .dotm). I know there are several ways to figure this out (like check file extension), but I am looking for the most "safe" one. My current guess is: Private Function isTemplate(ByVal Doc As Document) As Boolean isTemplate = (Doc.FullName = Doc.AttachedTemplate.FullName) End Function This works as expected, but I would like to know if there is a more fashioned way to achieve this goal.

Macros not showing up in the run macro menu

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 12:31:44
问题 I started learning VBA and I don't understand why some macros copy-pasted from the internet do not show up in the run macro menu (Alt-F8). Below there are 2 macros, but only the second one is showing. Why? And how do I fix it? Sub Test1(ByVal Target As Hyperlink) '... End Sub Sub Test2() '... End Sub 回答1: Macros with arguments are not available in Macros list because they cannot be run alone instead they are called by another macro by passing the required arguments. 回答2: If a Sub declaration