word-vba

MS-Word: Cross reference to custom reference type

百般思念 提交于 2019-12-10 19:41:38
问题 I'm trying to add a cross reference into a SEQ field. My document contains "point headings" which means that between two heading elements, the user can add an extension (between 1.1 and 1.2 may be 1.1A, 1.1B, ...) Here is how the point heading code looks like: {STYLEREF "HEADING 2" \N}{SEQ "HEADING 2 POINT" \* ALPHABETIC \S 2} Which results with: 1.1A I want to be able to do a cross reference into the point heading. While I can set the reference type into 'Heading' I can't find out how to

How do I delete a command button using Word VBA?

可紊 提交于 2019-12-10 17:44:01
问题 I have a Word document that contains a command button named "update". How can I delete this button using VBA? 回答1: This should do it : For Each o In ActiveDocument.InlineShapes If o.OLEFormat.Object.Name = "update" Then o.Delete End If Next 回答2: I think when you said 'Button Name' you ment 'Button Caption'; please try below code - For Each o In ActiveDocument.InlineShapes If o.OLEFormat.Object.Caption = "update" Then o.Delete End If Next Regards, Nilesh PS: the caption is case sensitive, so

How do I detect a Word table with (horizontally) merged cells?

牧云@^-^@ 提交于 2019-12-10 16:15:58
问题 When a Word table contains horizontally merged cells, accessing aTable.Columns.First or performing a For Each over aTable.Columns will result in an error. Is there a way to determine if a table contains horizontally merged cells without resulting in an error? I've read Determine if a Word cell is merged, but that is about detecting if a particular Word table cell is merged, rather than does the whole table have any merged cells. 回答1: Found a reference in this article to a Uniform property on

Make the first letter bold on each sentence in MS Word document

。_饼干妹妹 提交于 2019-12-10 15:38:27
问题 I'd like to make first letter on each sentence bold in a MS Word document. What would be a good way to accomplish this? 回答1: Pretty straight-forward in VBA Sub BoldFirstLetterInSentence() Dim ad As Document Set ad = ActiveDocument Dim sen As Range For Each sen In ad.Sentences sen.Words.First.Characters.First.Font.Bold = True /* sen.Words(1).Characters(1).Font.Bold = True also works */ Next End Sub 回答2: This can be done with Word's built in advanced find+replace. You would need to specify a

Word macro, storing the current selection (VBA)

北战南征 提交于 2019-12-10 15:23:17
问题 I have a Word document that contains about 4000 form fields which I have to export afterwards to a database. The matter is that none of the 4000 fields have an information in the "Bookmark" field, thus I cannot get the information stored in them. I'm trying to create a macro to help the process of writing the bookmark (FormField.Name) but cannot manage to do it right. The matter is that I want to change the names of the FormFields contained in the user's selection, and only them. I've managed

How to trim table cell values in MS Word with VBA

本小妞迷上赌 提交于 2019-12-10 14:52:04
问题 I have a table in a Word file. This vba program below will iterate through all the table cells Dim strCellText As String Dim uResp As String Dim Row As Integer Dim Col As Integer Dim itable As Table For Each itable In ThisDocument.Tables uResp = "" For Row = 1 To itable.Rows.Count For Col = 1 To itable.Columns.Count strCellText = itable.Cell(Row, Col).Range.Text uResp = uResp & Trim(strCellText) Next Next MsgBox uResp Next In the line uResp = uResp & Trim(strCellText) VBA appends a newline

Make VBA code undo in one step

倾然丶 夕夏残阳落幕 提交于 2019-12-10 13:46:42
问题 Is there a way to make VBA code of a Word 2013 macro execute as block, so if I undo it, it doesn’t undo the macro by the individual steps it goes through to execute? I would like macros to act more like built in functions. I have macro that moves the cursor to the end of a word then deletes the previous three letters. If I undo it, I see each of the three letters reappear one by one. I may not have worded this right. I was wondering if there was code to wrap a macro in to get Word to treat a

Detecting when data is added to a document, eg. a character or white space

喜你入骨 提交于 2019-12-10 13:07:15
问题 Is there a way to detect when a user presses a key in Microsoft Word using VBA. I have searched for a method which does this. I have also searched for methods which create a way around this, such as detecting when the insertion point moves or it detects when a new character is placed in the word document, but I have had no look. I am currently using appWord_WindowSelectionChange(ByVal Sel As Selection) but this does not detect as you type. I would appreciate anyone showing me how to either

Extract Headings and Pagenumber of Table of Contents of a Word Document with VBA

拟墨画扇 提交于 2019-12-10 12:58:25
问题 Basically what we have here Getting the headings from a Word document Public Sub CreateOutline() Dim docOutline As Word.Document Dim docSource As Word.Document Dim rng As Word.Range Dim astrHeadings As Variant Dim strText As String Dim intLevel As Integer Dim intItem As Integer Set docSource = ActiveDocument Set docOutline = Documents.Add ' Content returns only the ' main body of the document, not ' the headers and footer. Set rng = docOutline.Content astrHeadings = _ docSource

Word VBA force save as .docm

梦想与她 提交于 2019-12-10 12:26:30
问题 I've ended up cleaning up someone's mess on a Word document that's used throughout my company. It is a macro-heavy document that needs to be saved as a .docm exclusively. I'm worried about it getting "save as"-d as something other than a .docm , but I can't seem to find a way to limit the save as file picker or swap out the extension on save as while still using VBA. How can I achieve this? Edit: Some of the things I've tried, to no avail: This has the right idea, but doesn't actually limit