![]() |
#1
|
|||
|
|||
![]()
At a high level, I am building a format command, within VBA, like,
"ActiveDocument.Words(intWordPointerL).Font.It alic = True" I then want to execute the command. At first it seemed like "Eval" or "Application.Run" might be a solution, but I haven't gotten them to work. Seems like they are looking for existing function/sub references, rather than a free form string. I'd like something like the PowerShell Invoke-Expression command. To simplify, I'm working with the base command, preformed, "ActiveDocument.Words(intWordPointerL).Font." Then appending one of a variety of qualifiers, like "Italic = True". Tried using "Eval". Tried using Application.Run. Both seem to require a reference to and existing Macro. If I can't invoke the command directly, can I create a macro on the fly and then invoke it? I found this answer to a similar question relative to Excel, VBA - Execute string as command in Excel - Stack Overflow If it works in Excel, it could probably be adapted to work in Word. I'm not strong in VBA. I don't understand how to convert this Excel-centric code for MS-Word usage. ================================================== =========================== Sub test() Set VBComp = ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_S tdModule) VBComp.Name = "NewModule" Set VBCodeMod = ThisWorkbook.VBProject.VBComponents("NewModule").C odeModule Dim l_counter As Long l_counter = 1 With VBCodeMod LineNum = .CountOfLines + 1 .InsertLines LineNum, _ "Sub MyNewProcedure()" & Chr(13) & "UserForm1.chb_g_ba" & l_counter & ".Visible = True" & Chr(13) & "End Sub" End With 'run the new module Application.Run "MyNewProcedure" UserForm1.Show 'Delete the created module ThisWorkbook.VBProject.VBComponents.Remove VBComp End Sub |
#2
|
|||
|
|||
![]()
I moved your post to the vba forum.
However, I strongly urge you to learn to use Styles rather than direct formatting. The Importance of Styles in Microsoft Word You can put all of your formatting into a style and simply apply the style. You can assign a keyboard shortcut to a style just as you can to a macro. This will make for documents that are more efficient (smaller) and easier to edit. |
#3
|
|||
|
|||
![]()
Cross posted and answered at Redirecting
For cross-posting etiquette, please read: A Message to Forum Cross-Posters |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Show table list by using chek box command and save document on sharepoint by using command button | Zhibek | Word VBA | 3 | 08-16-2018 06:19 PM |
![]() |
wardw | Word | 7 | 05-07-2018 09:13 AM |
Using MSWord 2003 docs in MSWord 2010 | Joe Watson | Word | 7 | 05-31-2014 11:27 AM |
![]() |
omahadivision | Excel Programming | 12 | 11-23-2013 12:10 PM |