word-vba

Duplicate removal for VBA Word not working effectively

本小妞迷上赌 提交于 2019-12-23 02:31:10
问题 I have a program to remove duplicates and everything is working properly. It is just freezing with large data sets i.e. 1 to 2.5 million words. What is wrong with my approach? Is there a better one? Sub DeleteDuplicateParagraphs() Dim p1 As Paragraph Dim p2 As Paragraph Dim DupCount As Long Dim StartTime As Double Dim SecondsElapsed As Double StartTime = Timer For Each p1 In ActiveDocument.Paragraphs If p1.range.Text <> vbCr Then For Each p2 In ActiveDocument.Paragraphs If p1.range.Text = p2

Running python from VBA word and returning a value

◇◆丶佛笑我妖孽 提交于 2019-12-23 01:44:12
问题 Trying to figure out how to open python from word vba, on mac computers, and return a value using the code below. I need to be able to run this code from word vba without calling a specific python file, this will be run on multiple computers so I can't assume they have my premade python file downloaded. All I've seen is people calling a premade file with the script already in it. Here is my Python Code: import urllib2 web1 = urllib2.urlopen('website.com') #website url print(web1.read()) Any

Generate bookmarks in Word 2010 programmatically, with the header name as the bookmark name

北慕城南 提交于 2019-12-23 01:42:36
问题 I need to generate bookmarks in Word 2010 programmatically, with the header name as the bookmark name. I have the following code which makes a word a bookmark, but the bookmark name remains the same as the string Heading 1 is only available in the name variable: Sub bookmarking() Selection.EndKey Unit:=wdLine, Extend:=wdExtend With ActiveDocument.Bookmarks .Add Range:=Selection.Range, Name:=" Heading 1" .DefaultSorting = wdSortByName .ShowHidden = False End With End Sub Instead of the Heading

VBA Word: I would like to find a phrase, select the words before it, and italicise the text

人盡茶涼 提交于 2019-12-22 18:24:04
问题 I'm having trouble with VBA commands to find a certain phrase, then select the 1 or 2 words before it, and then italicize the entire thing. I'm able to use the Selection.Find , Font.Italicise , and wdExtend commands independently of each other, but when I combine them to perform this task, the macro just crashes. Any help? Selection.Find.ClearFormatting With Selection.Find .Text = "Michael" .Replacement.Text = "Michael" .Forward = True .Wrap = wdFindStop Do While .Execute() = True Selection

Select ListBox item on rightclick in Word VBA

岁酱吖の 提交于 2019-12-22 18:15:21
问题 I'm developping a project in Word 2003 with VBA. I have a multiselect ListBox with some entries (dates). On rightclick I'd like to have an InputBox popping up where the user can change the selected date. This works well, as long a specific item is already focused (not only selected, but focused). But, if you rightclick on an item without focus, the box shows up and changes the date of the focused entry, not always the one you rightclicked. I found this answer (http://www.vbarchiv.net/tipps

Range.InsertXML using Transform

旧巷老猫 提交于 2019-12-22 12:54:09
问题 I am using Range.InsertXML to add formatted content to an existing MS Word document. AFAICT, the method .InsertXML takes parameters XML as a string and XLST (Transform) as a variant; however the documentation for .InsertXML is lacking in that it does not provide an example that includes the use of Transform. In responding to this question: Range.InsertXML throws when inserting Open XML Cindy Meister linked to an excellent resource that explains lotd about Words XML and how to use it, but I

Range.InsertXML using Transform

♀尐吖头ヾ 提交于 2019-12-22 12:53:59
问题 I am using Range.InsertXML to add formatted content to an existing MS Word document. AFAICT, the method .InsertXML takes parameters XML as a string and XLST (Transform) as a variant; however the documentation for .InsertXML is lacking in that it does not provide an example that includes the use of Transform. In responding to this question: Range.InsertXML throws when inserting Open XML Cindy Meister linked to an excellent resource that explains lotd about Words XML and how to use it, but I

How to insert text into TextBox in Word Macro

岁酱吖の 提交于 2019-12-22 10:28:13
问题 I created a text bo in the Word and I would like to insert text into it: Sub k() Dim Box As Shape Set Box = ActiveDocument.Shapes.AddTextbox( _ Orientation:=msoTextOrientationHorizontal, _ Left:=50, Top:=50, Width:=100, Height:=100) //HOW TO INSERT HERE TEXT INTO TEXT BOX End Sub 回答1: Here is the solution: Sub k() Dim Box As Shape Set Box = ActiveDocument.Shapes.AddTextbox( _ Orientation:=msoTextOrientationHorizontal, _ Left:=50, Top:=50, Width:=100, Height:=100) 'The solution for you: Box

Word vba - if cursor is in cell / bookmark - run code

血红的双手。 提交于 2019-12-22 09:16:29
问题 I have a template document which contains several sections and a few tables. The thing is, I'm trying to insert a drop-down list inside on of the cells in the table. And for a drop-down list to work, the document needs to be protected. But if I protect the entire section the table is in, the entire table is protected. So, I was wondering if there's a way of executing a macro code IF the user clicks on the drop-down list? The code would then protect the document, making the control actually

Copy and paste an excel chart with a VBA macro in word

删除回忆录丶 提交于 2019-12-22 07:09:12
问题 I'm aware that my question may sound/be trivial, but I couldn't find the solution anywhere...and I'm exhausted. I'm writing a macro to automatize a report generation in Word. At some stage, I need to insert some chart, which is located as a chartsheet from excel...but no way. Here's my code Sub copy_pic_excel() Dim xlsobj_2 As Object Dim xlsfile_chart As Object Dim chart As Object Set xlsobj_2 = CreateObject("Excel.Application") xlsobj_2.Application.Visible = False Set xlsfile_chart = xlsobj