word-vba

VBA Pass arguments with .onAction

亡梦爱人 提交于 2019-11-26 21:51:22
问题 this is how my sub looks like: Sub InsertRowWithContent(rowNo As Long) This is my .onAction: .OnAction = "'InsertRowWithContent""" & C & """'" C is a Long variable declared earlier. It says macro not found. It worked fine before adding an argument! 回答1: I have sucessfully passed arguments with this syntax: .OnAction = "=InsertRowWithContent(" & C & ")" Considerations: C is a long. So don't add quotas, just as you wouldn't if you would call the Sub in the code. OnAction evaluates an expression

Getting the headings from a Word document

帅比萌擦擦* 提交于 2019-11-26 17:33:07
问题 How do I get a list of all the headings in a word document by using VBA? 回答1: You mean like this createOutline function (which actually copy all headings from a source word document into a new word document): (I believe the astrHeadings = _docSource. GetCrossReferenceItems (wdRefTypeHeading) function is the key in this program, and should allow you to retrieve what you are asking for) Public Sub CreateOutline() Dim docOutline As Word.Document Dim docSource As Word.Document Dim rng As Word

Repeating Microsoft Word VBA until no search results found

对着背影说爱祢 提交于 2019-11-26 17:01:58
问题 I've created a MS Word macro that searches for certain text (indicated by markup codes), cuts the text and inserts it into a new footnote, and then deletes the markup codes from the footnote. Now I want the macro to repeat until it doesn't find any more markup codes in the text. Here's the macro below Sub SearchFN() 'find a footnote Selection.Find.ClearFormatting With Selection.Find .Text = "&&FB:*&&FE" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase =

Get list of sub-directories in VBA

喜你入骨 提交于 2019-11-26 03:16:48
问题 I want to get a list of all sub-directories within a directory. If that works I want to expand it to a recursive function. However my initial approach to get the subdirs fails. It simply shows everything including files: sDir = Dir(sPath, vbDirectory) Do Until LenB(sDir) = 0 Debug.Print sDir sDir = Dir Loop The list starts with \'..\' and several folders and ends with \'.txt\' files. EDIT: I should add that this must run in Word, not Excel (many functions are not available in Word) and it is