word-vba

Select a all tables within table using Word Macro

走远了吗. 提交于 2020-01-17 07:25:35
问题 I have these documents that I get regularly that I have to format and all the data is stored within tables that reside inside larger tables for layout purposes. I'd like to style the column widths of the tables within tables if it's possible with a macro? 回答1: You can reference the nested tables directly. With the following command you get the number of tables contained in the first table in the document. Debug.Print ThisDocument.Tables(1).Tables.Count You can then loop through them and

Can a character style be applied programmatically to a string before it is written to the Word document with VBA?

青春壹個敷衍的年華 提交于 2020-01-16 16:57:23
问题 I am grabbing some data from an Excel sheet and populating it into a Word template. I'm hoping that I can assign some of the Document's character styles to sub strings that will be added to the Document as the string is built up rather than having add the string to the Document and then select each string individually to apply the appropriate style. Right now, I'm concatenating a few strings and adding them to a text box in the document like this: ActiveDocument.Shapes("Text Box 7").TextFrame

Inserting formatted numbers as text in Right to Left MS-Word document

对着背影说爱祢 提交于 2020-01-16 13:14:28
问题 I have sValA = 10/140/000 string. Need inserting 10/140/000 as text in a right-to-left document. When I performs below ThisDocument.Bookmarks("Temp_GrandTotal").Range.Text = sValA It returns 000/140/10 Any helps are appreciated. 回答1: You can add a UDF to swap the parts by a swap character. Then call it like: ThisDocument.Bookmarks("Temp_GrandTotal").Range.Text = SwapParts(sValA,"\") UDF code: Option Explicit Function SwapParts(ByVal sText As String, ByVal SwapChar As String) As String Dim

How to use VBA to say 'Yes' to any SQL prompts in word?

房东的猫 提交于 2020-01-15 15:44:08
问题 I'm using a macro, launched from a word document, which opens, executes, and closes a series of other documents, each of which contains a macro that executes a mail merge. The code works fine, but each time the new document is opened, I am given an SQL prompt, asking if I want to put the data into my document from the datasource. I can just say 'Yes' to all of these dialog boxes, but a) I would like to automate this to make it easier b) Other users might also use this document, and I don't

Convert text to image in Microsoft Word

梦想的初衷 提交于 2020-01-15 10:05:18
问题 I have a large book written in Microsoft Word and want to create a macro that will find all text using a predefined style and convert that text to an inline image. This text will be in Arabic and generally no longer than 4-5 lines. Is this possible? UPDATE: Here's an example to show what I'm referring to: I want to replace that entire line in Arabic with an image (as if I cropped this attached image to only include the Arabic and then replaced the line in Arabic with the image). The reason I

Convert text to image in Microsoft Word

ぐ巨炮叔叔 提交于 2020-01-15 10:03:14
问题 I have a large book written in Microsoft Word and want to create a macro that will find all text using a predefined style and convert that text to an inline image. This text will be in Arabic and generally no longer than 4-5 lines. Is this possible? UPDATE: Here's an example to show what I'm referring to: I want to replace that entire line in Arabic with an image (as if I cropped this attached image to only include the Arabic and then replaced the line in Arabic with the image). The reason I

How to run a VBA Macro by clicking Word 2010 Checkbox?

送分小仙女□ 提交于 2020-01-14 09:17:28
问题 I want to run a macro when I click a checkbox in Word 2010 . Note that I neither want the "Legacy Forms" checkbox nor the "ActiveX" ones! They do only work in some "protected document mode" and look ugly, but I want the new ones which can be selected and unselected just when you write the document, and which look much nicer to me. I know, with the legacy forms, you can directly insert a Macro when entering the form element and one for leaving it, and you can catch the event in VBA like Sub

How to run a VBA Macro by clicking Word 2010 Checkbox?

╄→гoц情女王★ 提交于 2020-01-14 09:17:09
问题 I want to run a macro when I click a checkbox in Word 2010 . Note that I neither want the "Legacy Forms" checkbox nor the "ActiveX" ones! They do only work in some "protected document mode" and look ugly, but I want the new ones which can be selected and unselected just when you write the document, and which look much nicer to me. I know, with the legacy forms, you can directly insert a Macro when entering the form element and one for leaving it, and you can catch the event in VBA like Sub

How to check until file exist

怎甘沉沦 提交于 2020-01-14 06:03:49
问题 Is there any way to check until file exists in VBA. what I am trying to do is, making vba call asynch. Now after I run wshShell.Run """" & SFilename & """" & s I want to check until file exists like this Wait until fso.fileexists("file") Msgbox "file is now available" End wait!!! is there any way in vba? I am using word vba. 回答1: You can do it like this: Do If fso.FileExists("file") Then Exit Do End If DoEvents 'Prevents Excel from being unresponsive Application.Wait Now + TimeValue("0:00:01"

Is there a way to trigger “track changes” through VBA in Excel?

喜你入骨 提交于 2020-01-13 20:30:10
问题 I want from VBA to start/stop "Track changes" functionality in Excel. Searching thru the Net I saw a property called TrackRevisions of ActiveDocument object. Supposedly in MS Word writing ActiveDocument.TrackRevisions = True should turn on "Track changes". But in MS Excel this line gives 424 Object required run-time error. Same error is returned when trying with ThisWorkbook . Changing it to ActiveSheet brings 438 Object doesn't support this property or method error. 回答1: For a shared