word-vba

Passing Argument with Application.Run in Word VBA

随声附和 提交于 2019-12-18 08:55:27
问题 I have the following two Sub defined in my Word Addin (.dotm) which I have put in StartUp directory Public Sub SayHi1() MsgBox "Hi......." End Sub Public Sub SayHi2(ByVal n As String) MsgBox "Hi " & n End Sub Then from a new document I am able to call 1st Sub without argument as below: Sub AppRun_AddIn_NoArg() Application.Run "MyProject.Module1.SayHi1" End Sub But when I try to run the 2nd Sub with argument I get error saying "Object doesn't support this property or method" Sub AppRun_AddIn

Word occurences in VBA: how to speed up

牧云@^-^@ 提交于 2019-12-18 07:23:15
问题 I need to write a MS Word macro to count occurence of every word within a given document and print out the list like . I did the macro and it works, but it is so sloooow, it takes several hours to get results for a document of 60000 words. Could you please give me some advices/suggestions on how to make the macro run faster? (I checked a similar question here WORD VBA Count Word Occurrences but still don't get it how to speed up and need my macro to be reviewed). Thank you. Private Type

VBA WORD: Remove double paragraph marks

僤鯓⒐⒋嵵緔 提交于 2019-12-18 07:16:15
问题 Trying to move excessive paragraph gaps via this procedure. Sub RemoveGaps() wrdDoc.Content.Select Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "^13^13" .Replacement.Text = "^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = True .MatchWildcards = True End With Selection.Find.Execute Replace:=wdReplaceAll If Selection.Find.Found = True Then Call RemoveGaps End If End Sub After I run it the

Linked Table in MS Word

余生长醉 提交于 2019-12-18 05:17:05
问题 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

Getting char from string at specified index in the visual basic

假如想象 提交于 2019-12-18 04:33:06
问题 As stated how to get char from string at specified index in the visual basic? I look through google and these do not work: s(index) , s.Chars(index) , s,Characters(index) So how to get char at specified index? 回答1: If s is your string than you could do it this way: Mid(s, index, 1) Edit based on comment below question. It seems that you need a bit different approach which should be easier. Try in this way: Dim character As String 'Integer if for numbers 's = ActiveDocument.Content.Text - we

Modify embedded Excel workbook in Word document via VBA

泄露秘密 提交于 2019-12-18 04:10:33
问题 I have a Word document with two embedded Excel files (added using Insert -> Object -> Create From File) which I wish to modify using Word VBA. I have got to the point where I am able to open the embedded files for editing (see code below), but am unable to get a handle on the Excel workbook using which I can make the modifications and save the embedded file. Does anyone have a solution for this? Thanks in advance. Sub TestMacro() Dim lNumShapes As Long Dim lShapeCnt As Long Dim xlApp As

Modify embedded Excel workbook in Word document via VBA

梦想与她 提交于 2019-12-18 04:10:18
问题 I have a Word document with two embedded Excel files (added using Insert -> Object -> Create From File) which I wish to modify using Word VBA. I have got to the point where I am able to open the embedded files for editing (see code below), but am unable to get a handle on the Excel workbook using which I can make the modifications and save the embedded file. Does anyone have a solution for this? Thanks in advance. Sub TestMacro() Dim lNumShapes As Long Dim lShapeCnt As Long Dim xlApp As

Add an Image to Word Document and Scale it using VBA

时光毁灭记忆、已成空白 提交于 2019-12-18 03:38:11
问题 how do i programatically add an image using VBA to a word document. I've tried adding a bookmark to the word document and tried adding the image, but it always adds to the top of the form rather than the bookmark area. Should i persevere with the bookmark or is there another way to add the image? See my code below: Dim wrdApp As Word.Application Dim wrdDoc As Word.Document Set wrdApp = CreateObject("Word.Application") Dim objWdRange As Word.Range Dim GraphImage As String Dim shortString As

Suppress unwanted jumping/scrolling on Word 2013 VBA Script

混江龙づ霸主 提交于 2019-12-17 21:12:41
问题 When accessing Legacy Form Field values in my Word 2013 document like this (getting or setting): ' get myField = ActiveDocument.FormFields("myField").Result ' set ActiveDocument.FormFields("myField").Result = myValue the document weirdly jumps/scrolls down and up and stops at a complete different position (it seems to jump to the lines where the referred fields are positioned). Have a look at this screencast or a sample file where the error can be viewed. I have used Application

How-to: Run existing Word VBA Macros from C# Ribbon Addin

非 Y 不嫁゛ 提交于 2019-12-17 19:53:42
问题 Background: I have an extensive set of specialized VBA macros used in Word for document formatting purposes. In Word 2003, these macros were activated from a customized toolbar. I have recently transitioned to Word 2007 and would like to be able to run these existing VBA macros from a new Word Ribbon created with VS 2010. I have created a Ribbon; however, I cannot figure out how to call the existing macros from the new Ribbon buttons. Question: How do I call the existing VBA macros, which are