word-vba

MS Word Macro - Delete Paragraphs

廉价感情. 提交于 2019-12-01 09:27:38
问题 Could somebody please help me with a MS Word Macro that would search for a specific symbol in every paragraph throughout the document and delete paragraphs that DO NOT contain that symbol. I know practically nothing about VBA, but just received a huge & unwieldy document I need to edit real fast. 回答1: Here's a quick macro that should do what you want - use with caution, and don't forget to backup! Set the value of 'search' to be the text that you're looking for. It's very crude, and will

Text of the preceding heading in word

限于喜欢 提交于 2019-12-01 09:18:59
Given any selected word or paragraph in Word, is there a way to use VBA to find the text of the nearest preceding heading? For example: Heading Level 1: The Main Title This is a paragraph about the document. (A) Heading Level 2: A Sub Title This paragraph describes a detail.(B) If any part of (B) is selected, I want to find "A Sub Title". If any part of (A) is selected, I want to find "The Main Title". Is this what you are trying? Option Explicit Sub Sample() Do Selection.MoveUp Unit:=wdLine, Count:=1 Selection.HomeKey Unit:=wdLine Selection.EndKey Unit:=wdLine, Extend:=wdExtend If

copy-paste tables from word to excel

ε祈祈猫儿з 提交于 2019-12-01 08:05:29
I have a word document which is updated periodically. I can go into that Word document, select the contents of an entire table and copy, then go into an Excel spreadsheet and paste it. It's screwed up; however, I fix it as follows: sht.Cells.UnMerge sht.Cells.ColumnWidth = 14 sht.Cells.RowHeight = 14 sht.Cells.Font.Size = 10 This manual copy-paste works regardless of whether the table is has merged fields. Then I can start to manipulate it manually: parsing, checking, computations, etc. I can do this one table at a time, but it's tedious and of course error prone. I want to automate this. I

Event - Document Edited

坚强是说给别人听的谎言 提交于 2019-12-01 07:54:25
问题 Is there an event for when a document is edited? If not, does anyone know where I could find a list of the available VBA events? 回答1: Here are the events for the document object: http://msdn.microsoft.com/en-us/library/aa140279(office.10).aspx Events DocumentBeforeClose : Immediately before any open document closes. DocumentBeforePrint : Before any open document is printed. DocumentBeforeSave : Before any open document is saved. DocumentChange : A new document is created, when an existing

Word VBA to retrieve IP address “silently”

血红的双手。 提交于 2019-12-01 06:31:49
I need to pull out the IP address into a VBA macro. This code works but the command dialogue is briefly visible which is not a good look. Can I use a modification to do it "silently" ? Sub getIP() Set objShell = CreateObject("WScript.Shell") Set objExecObject = objShell.Exec("%comspec% /c ipconfig.exe") Do Until objExecObject.StdOut.AtEndOfStream strLine = objExecObject.StdOut.ReadLine() strIP = InStr(strLine, "Address") If strIP <> 0 Then IPArray = Split(strLine, ":") strIPAddress = IPArray(1) End If Loop SynapseForm.LabelIP.Caption = strIPAddress End Sub Update , found a variant using

Text of the preceding heading in word

≯℡__Kan透↙ 提交于 2019-12-01 05:53:23
问题 Given any selected word or paragraph in Word, is there a way to use VBA to find the text of the nearest preceding heading? For example: Heading Level 1: The Main Title This is a paragraph about the document. (A) Heading Level 2: A Sub Title This paragraph describes a detail.(B) If any part of (B) is selected, I want to find "A Sub Title". If any part of (A) is selected, I want to find "The Main Title". 回答1: Is this what you are trying? Option Explicit Sub Sample() Do Selection.MoveUp Unit:

copy formatted text into access using vba

人走茶凉 提交于 2019-12-01 04:18:37
I need to save formatted text from Word in an Access Database. So far I've managed to figure out how to store formatted text in an Access Field (Create a Memo Field in a Table and set the Text Format as Rich Text). Searching SO I have not yet come across a solution as to how to transport said text from word into Access. I know that it is possible, because you can do it by simply copying and pasting the information if you are doing it manually. My question, how can I copy formatted text from word into a field in a table using VBA? Experimentally I created the following to test this. So far

Change all links' sources in a Word document - Misplacement of Ranges

六眼飞鱼酱① 提交于 2019-12-01 03:22:31
I work on this code to change the sources of all linked Fields/Charts/... in Word templates to the workbook it is launched from. I had usual fields and charts (which are stored in InlineShapes ), so I have 2 loops for every template. These loops sometimes stays stuck with For Each , and keep looping on Fields / InlineShapes (and don't even increase index...) without stopping. (I added the DoEvents for that, and it seems to reduce the frequency of that happening... if you have an explanation, it'll be very welcome! ) And with For i = ... to .Count , now it works pretty much flawlessly, except

Change all links' sources in a Word document - Misplacement of Ranges

社会主义新天地 提交于 2019-12-01 00:12:56
问题 I work on this code to change the sources of all linked Fields/Charts/... in Word templates to the workbook it is launched from. I had usual fields and charts (which are stored in InlineShapes ), so I have 2 loops for every template. These loops sometimes stays stuck with For Each , and keep looping on Fields / InlineShapes (and don't even increase index...) without stopping. (I added the DoEvents for that, and it seems to reduce the frequency of that happening... if you have an explanation,

Find all instances of yellow text and change font color to red

大城市里の小女人 提交于 2019-11-30 22:11:47
I need a vba macro that searches for all text that has font color as yellow within a MS Word 2007 document and changes it to red. The yellow color won't show in the printouts. Manually selecting and changing will take me hours. Following on from stakx’s Word 97 solution, here’s what works in Word 2010: Open the Find and Replace dialogue (e.g. Ctrl-H) Click in the "Find what" box. Format drop-down, Font, choose the Font color to be found, OK. Click in the "Replace with" box. Format drop-down, Font, choose the colour to end up with, OK. Observe that the Format: description for "Find what" and