word-vba

Need to capture current scroll position (not cursor position) in MS Word

℡╲_俬逩灬. 提交于 2019-12-11 10:21:36
问题 I need to get the current scroll position (I think that is the right term; i.e., where is my virtual lens pointed at the document, not where my cursor is) in a Word document, so that when I run a macro I can return to that position at the end. I wrote a macro that searches backward from the current cursor position for patent application part numbers, determines a candidate next available part number as the previous max + 1, then searches a sorted list of numbers appearing below the cursor to

Transforming Word tables into Excel array

早过忘川 提交于 2019-12-11 09:42:32
问题 I am trying to transfer Word tables to Excel - this has already been done here - and in addition, during the transfer I'd like to keep only rows that contain certain content, and would like to reshape the table before pasting it into Excel. I thought this could be done by converting each table first into an Excel array and then modifying the array as needed before pasting it to a specified range. Yet, I am not so familiar with Word VBA and I am finding this task pretty hard. I am starting

Search text with Content.Find object in Word with VBA and recover the text found

[亡魂溺海] 提交于 2019-12-11 09:42:21
问题 I want to search an entire MSWord document for a text with wildcards and recover the strings found. something like that: Sub Macro1() Dim c As Range Set c = ActiveDocument.Contentsdf c.Find.ClearFormatting c.Find.Replacement.ClearFormatting With c.Find .Text = "start[abcde]end" .Replacement.Text = "" .Forward = True .wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = True .MatchSoundsLike = False .MatchAllWordForms = False ' End With c.Find.Execute

Find equations in word and save each out as separate file

。_饼干妹妹 提交于 2019-12-11 08:34:48
问题 I would like to go through a Word doc, using vba, to take each equation, save it to the clipboard, open a new blank doc, and save that out as a pdf file. I found two pieces of code which should help me get started but neither get very far: Sub get_eqns() Dim eqns As OMath Dim para As Paragraph For Each eqns In ActiveDocument.OMaths With eqns.Range.Select ' '~~> Rest of the code ' End With Next For Each para In ActiveDocument.Paragraphs If para.Range.OMaths(1) = True Then para.Range.OMaths(1)

How to add bullet in comment using Word VBA?

心不动则不痛 提交于 2019-12-11 08:16:26
问题 I want to add bullet in second line. Public Sub AddComment() Selection.Comments.Add Range:=Selection.Range With Selection .Font.Bold = True .TypeText "Test Bold: Bold Text" .TypeText "This text has bullet" & vbNewLine .TypeText "This is simple text" End With End Sub Above code add Font.Bold style in first line. I want to add bullet in second line only. In the third line, there should not have bullet. Can anybody please suggest me? 来源: https://stackoverflow.com/questions/39292065/how-to-add

Word VBA copy highlighted text to new document and preserve formatting

梦想与她 提交于 2019-12-11 07:54:35
问题 I have a word document with multiple highlighted words that I want to copy into another word file. The code I'm using works fine, but does not preserve the original formatting in the source document. Here's the entire code (1st section finds words using wildcards and highlights them, and the 2nd section finds the highlighted words and copies them to a new word document): Sub testcopytonewdoc2() ' Dim ThisDoc As Document Dim ThatDoc As Document Dim r, newr, destr As Range Dim rangestart,

Checkbox to modify textbox in Word 2010

天大地大妈咪最大 提交于 2019-12-11 06:57:08
问题 I want to have a MS Word 2010 document where there is a checkbox (ckeckable) and a textbox (textfield) where different text is displayed depending on whether the checkbox is clicked or not. I have tried searching for it but somehow all the suggestions are not meant as solutions for the checkbox question... I would think that the solution should be used in Visual Basic? 回答1: Something like this? Private Sub CheckBox1_Change() If CheckBox1.Value = True Then TextBox1.Text = "Checked!" Else

Error in a Word VBA macro, trying to insert values into bookmarks

自古美人都是妖i 提交于 2019-12-11 06:35:43
问题 I'm trying to write a Word macro which inserts data from the Current User in Registry into predefined bookmarks in the document. I've got an ini-file which dictates what the names of each registry entry is, and that value is then imported into a loop in the Word Macro. This works fine (I think), but the Word macro needs to insert the data into the document as well. And this works fine if the bookmarks are there, but if they aren't, the macro seems to insert data anyway. I don't want that. I

Convert a Word Range to a String with HTML tags in VBA

巧了我就是萌 提交于 2019-12-11 06:32:34
问题 I have a Word document and I need to copy some paragraph of it into a string in VBA. When doing so, the text formatting must be converted to HTML tags. For example if my paragraph looks like this: Hello I am Alice . I want to get a string that contains: Hello I am <b>Alice</b> (And it would be great if it also work for bulleted list and other kind of formatting). I am using Microsoft Visual Basic for Applications 7.0. I am new to VBA and a lot of code I found on Internet does not work for me

Get heading number from previous heading

左心房为你撑大大i 提交于 2019-12-11 06:28:10
问题 This Word macro written by Paul Beverley adds a comment to the document and inserts the page and line numbers. Sub CommentAdd() ' Version 20.02.12 ' Add a comment ' Ctrl-Alt-# attrib1 = "PB: " attrib2 = "PB: " postText = "" keepPaneOpen = False addPageNum1 = True addLineNum1 = True addPageNum2 = True addLineNum2 = True highlightTheText = False textHighlightColour = wdYellow colourTheText = False textColour = wdColorBlue Set rng = Selection.Range rng.Collapse wdCollapseEnd rng.MoveEnd , 1