word-vba

ActiveX control of Word. Select text and images

核能气质少年 提交于 2019-12-12 04:48:04
问题 This is what I have done so far: word = actxserver('Word.Application'); document = word.documents.Open('C:\Documents and Settings\kz7213\Desktop\Test.docx'); selection = word.Selection; selection.TypeText('Big Finale'); selection.Style='Heading 1'; selection.TypeParagraph; FIG1 = figure('Visible','off'); plot([1 2 3 4 5],[4 1 3 5 7]); print -dmeta selection.Paste; selection.Style='Heading 1'; selection.InsertCaption('Figure','Test figure 1'); %Not working selection.Style='CaptionStyle';

Using VBA in Word 2010 to change column widths in a table

此生再无相见时 提交于 2019-12-12 04:46:51
问题 I am just getting started with VBA, using my old copy of Word 2010. I want to resize two of the columns in a three column table and format the text that is in the columns. This code was generated by Word's macro recorder: Selection.ConvertToTable Separator:=wdSeparateByCommas, NumColumns:=3, _ NumRows:=14, AutoFitBehavior:=wdAutoFitContent With Selection.Tables(1) .Style = "Table Grid" .ApplyStyleHeadingRows = True .ApplyStyleLastRow = False .ApplyStyleFirstColumn = True .ApplyStyleLastColumn

Automatically move MS Word bookmark after an insertion at this point

会有一股神秘感。 提交于 2019-12-12 04:40:00
问题 H ey folks, I've assembled the following code, which copies the first table in my Word document and inserts it at a bookmark position and also adds a formated heading above it via a second bookmark. To fully automate my Excel application however, I need an advanced functionality of my code. After an insertion was done, the bookmarks have to be relocated to a position directly above the newly inserted table / heading. Is it possible to relocate these bookmarks programmatically? Any help is

MS word 2016 Macro

杀马特。学长 韩版系。学妹 提交于 2019-12-12 04:37:01
问题 I am new to VBA but I have a word 2016 template and it has the following sections: Base Amount: $ Service Fee: $ Sales Tax % $ Other tax %: $ Tax 2 %: $ My goal is if an amount is missing from any of the lines, then delete that line. I tried recording the macro and then making changes but no luck. Sub TEST() Dim i As Long With Selection.Tables(1) For i = .Rows.Count To 1 Step -1 If Len(.Cell(i, 2).Range.Text) = 2 Then .Rows(i).Delete End If Next i End With End Sub 回答1: I've added : the

Find.replace with loop doesn't work the way I want

≯℡__Kan透↙ 提交于 2019-12-12 04:14:02
问题 What I want to do: Go through a document and look for word1 Replace word1 with word2 Change the word2 (increment it) Do 1-3 until word1 is replaced everywhere My code so far: With ThisDocument.Range.Find ' search the Document .Text = "RS.0569/14.xxxxx" ' for this text .Replacement.Text = nextID ' replace it with an ID ( Start= 0 ) Do ' loop the .execute part to increment my ID and only touch one ID at a time .Execute Replace:=wdReplaceOne ' only replace one word per loop nextID = Val(Split

Grouping shapes VBA word macro

爷,独闯天下 提交于 2019-12-12 04:07:41
问题 I'm trying to optimise my macro which allow me to ungroup all the shapes that are located in that active Page and if those shapes are already Ungrouped this macro will Group them What I want to do is to modify this code to allow to group and Ungroup all in the Active page only not all te document . I'm a little noobi with VBA this is my code Private Sub degroupage_Click() Dim mydocument As Document Set mydocument = ActiveDocument On Error Resume Next ActiveDocument.Unprotect 'enregistré

How to remove Top blank lines in VBA office word

北慕城南 提交于 2019-12-12 03:49:28
问题 How i can delete Only the blank lines at the top of each page in VBA word 2016. I tried to do something like this Sub RemoveBlankParas() Dim para As Paragraph For Each para In ActiveDocument.Paragraphs If Len(para.Range.Text) = 1 Then 'only the paragraph mark, so.. para.Range.Delete End If Next para End Sub But the problem with that code is that it removes all blank lines not only at TOP of the page but also at the center or bottom of the page. Also if you can implement removing blank pages

VBA syntax to find an if conditional statement field code

与世无争的帅哥 提交于 2019-12-12 03:46:49
问题 I am searching for the correct syntax for my macro to find an IF Conditional statement field code. I need to search for {IF{DOCVARIABLE"CODE"} = "YES" "A" "B"} to remove this and replace with "B" (the false statement). When searching for a word field like {DOCVARIABLE "CODE"} alone, I write as: Text1 = "CODE" but when there is an IF & Text & Yes & TRUE, FALSE like above, how do I write? 回答1: Consolidated comment (OP crossposted elsewhere): For that specific sequence, you can search for ^19IF

Extracting specific text from a Word file

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 03:39:53
问题 I have a Word document that has font sizes of 14 and 18, and the document is of 1500 pages. I have to make specific changes to the font 14 and font 18, and so after searching, I came across VBA for Word that would allow me to do this easily. Since I have never done VBA before, I tried this: Sub tryIt() If Selection.Font.Size = 18 Then MsgBox ("test") End If End Sub But it doesn't work... The msgbox() was just to see if it recognized the text properly. So how can I separate / differentiate

Word 2013: VBA Insert Content Control mapped to existing Custom XML

蹲街弑〆低调 提交于 2019-12-12 03:34:36
问题 I'm writing some VBA code to make it a bit easier for us to edit some of our documents - they're produced regularly, and are always different. We'd get some good value from content controls and custom XML, if only it would work. I've defined XML as follows (not the complete set of data): <document xmlns="http://example.com/dept/doctype"> <office> <address>123 Sample St</address> <city>Sampleville</city> </office> <customer> <address>456 Other St</address> <city>Otherville</city> </customer>