word-vba

programmatically inserting hidden text into a Word 2010 table

前提是你 提交于 2020-01-05 12:30:28
问题 I have a Word 2010 table with existing, visible text in it. I want to use some VBA code to insert some text into each cell and then hide the new text. I know how to insert text into a cell using VBA, I just can't figure out how to leave the existing text in the cell visible and only hide the new text. I tried this, but it doesn't quite work: For Each aTable In ActiveDocument.Tables Rows = aTable.Rows.Count Cols = aTable.Columns.Count Dim rng As Range For r = 1 To Rows For c = 1 To Cols

Copy Text from Table in Word and Retaing Formatting

流过昼夜 提交于 2020-01-05 11:58:24
问题 I have a problem copying a cell from a table to another cell. I'm talking about two word documents here. I can copy the text but the bullets are gone and some of the formatting. I tried .Formattedtext but still can't do it. Dim test As Word.Cell 'An error occurs something like "Object variable or With block variable not set" test.Range.FormattedText = CTPDoc.Tables(2).Rows(testCount).Cells(3).Range.FormattedText 回答1: Here is an example. Let's say we have two tables in a word document. See

Remove MS Word macro using VBScript

筅森魡賤 提交于 2020-01-05 09:07:30
问题 I want to remove all vba-modules from an MS Word template using VBScript. I wrote the following script. const wdDoNotSaveChanges = 0 WScript.Echo "starting Word..." Dim oApplication, doc Set oApplication = CreateObject("Word.Application") WScript.Echo "opening template..." oApplication.Documents.Open "path\to\test.dot" Set doc = oApplication.ActiveDocument Dim comp, components Set components = oApplication.ActiveDocument.VBProject.VBComponents For Each comp In components components.Remove

VBA script always returns Input past end of file error

早过忘川 提交于 2020-01-05 08:15:37
问题 I have a csv file as such: hello,world,this is,an,example, of,the,csv,file The first column will always be unique. I am getting the user to enter a string which matches an item in the first column, and the script returns the whole line: Open "C:\file1.csv" For Input As #file_number Do While (EOF(1) Or found = False) Line Input #file_number, raw_line pos = InStr(raw_line, fireName) If pos = Not 0 Then strData() = Split(raw_line, ",") found = True End If Loop Close #file_number If found = False

MS-Word VBA, Regex, replace format only of first capturing group

别说谁变了你拦得住时间么 提交于 2020-01-05 08:07:17
问题 I try to record a replacement in VBA using Search & Replace with wildcards: I have strings comprised of 3 white spaces followed by the word normal, like " normal", and want to replace the 3 leading spaces with "1 " (a 1 followed by two spaces) the "1" in a blue font. giving: "1 normal" with the 1 in blue and "normal" in the original format.. I tried to match: ([^s]{3})normal but when replacing with a new format I always get the whole string re-formatted.. how to preserve the original format

Why doesn't SaveAs use correct PixelsPerInch in macro?

旧巷老猫 提交于 2020-01-05 06:43:05
问题 I have a macro which converts Word docs to htm. The problem is that the images are always saved as 96 ppi, even though I have specified 240 ppi. Any ideas on how to fix? Here is my macro: Sub Doc2htm() With ActiveDocument.WebOptions .RelyOnCSS = True .OptimizeForBrowser = False .OrganizeInFolder = True .UseLongFileNames = True .RelyOnVML = False .AllowPNG = True .ScreenSize = msoScreenSize800x600 .PixelsPerInch = 240 .Encoding = msoEncodingWestern End With With Application.DefaultWebOptions

Iterate through pages in Word and find pages contains image

人走茶凉 提交于 2020-01-05 04:16:10
问题 I want to iterate though every page in a word document, check if that page contains an images or not, and do something about that page (Set page margin and insert a break). For Each Page in Document.Pages If Page.ContainsImage Then Page.TopMargin = 0 DoOtherStuff End If Next 回答1: A Document has a Shapes Collection representing all the Shapes. Each Shape has an Anchor , using which we can get to the TopMargin , and other properties, of the shape's page: Sub JiggleAllShapes() Dim shp As Shape

Extract embedded Excel worksheet data from Word

梦想的初衷 提交于 2020-01-04 06:07:53
问题 I have a batch of Word documents that have embedded Excel worksheets. Users have been entering data in the Excel sheet by double clicking the image of the sheet and opening an embedded Excel object. I need to get to the user entered data. Below is WORD VBA with a reference to the Microsoft Excel 15 library. (The Word and Excel object where created under Office 2010.) I can find the OLE object but I can't do anything with it. In the code below I tried to assign the object to a Worksheet object

How do I insert text at my cursor location in Word?

北慕城南 提交于 2020-01-04 00:12:39
问题 I'm trying to have my Excel macro insert some text at my cursor location in a already-opened Word Document. This is what I have written. I'm aware that the ActiveDocument.Range has the Start and End arguments, but I cannot seem to be able to assign them the "current selection" as a value. Help? Thanks? Sub InsertText() Dim rngTemp As Word.Range Set rngTemp = ActiveDocument.Range With rngTemp .InsertAfter "This is my sample text" .Font.Name = "Tahoma" .Font.Size = 11 .InsertParagraphAfter End

Find text only of style “Heading 1” (Range.Find to match style)

馋奶兔 提交于 2020-01-03 17:46:22
问题 I am trying to find some text in my document that only appears in "Heading 1" styles. So far, no avail. Sample Code: With ThisDocument.Range.Find .Text = "The Heading" .Style = "Heading 1" 'Does not work .Execute If .Found Then Debug.Print "Found" End With Just a note, it keeps stopping at the table of contents. Edit: fixed the mispelt 'if' statement 回答1: Your code looks good to me. My best guess is that the 'Heading 1' style exists in your table of contents? The code below should continue