word-vba

VBA: Why is Range.Find.Execute deselecting text in a Word doc?

白昼怎懂夜的黑 提交于 2019-12-11 02:19:44
问题 Why this VBA code ((initial part of a sub) modifies the visible selection in the Word document? I'm not modifying any selection. As per MSDN description: "If you've gotten to the Find object from the Range object, the selection isn't changed when text matching the find criteria is found, but the Range object is redefined. (Taken from: Find Object (Word)) So the following code should just modify the Range, and not affect the selection at all... Sub SelectTarget() Dim MyRange As Range Set

How to find and disable a content control by tag to delete it and its contents?

自古美人都是妖i 提交于 2019-12-11 01:56:02
问题 I have the unfortunate task of being forced to design a Word-based electronic production card for the unit at my company, even though I've never worked with VBA. I would much rather have done this in Excel since I wouldn't have to wrestle with content control and hard-to-find locations in various tables over the pages, but the company's documentation-system forces this particular one to be in Word. My issue is that for proper form of the production card I need to use tables, and I need the

Replace image inside Word bookmark from Excel

喜夏-厌秋 提交于 2019-12-11 01:49:01
问题 I have an open Word document with a bunch of bookmarks, each with an inline image of an Excel table previously exported from Excel. Now, I need to update the tables in the Word document as they have changed in Excel. The way I'm doing this is matching the table names in Excel with the bookmark names in Word. If they are equal than I want to replace the existing images in Word by the current ones. This is my code so far: Sub substituir() Set WordApp = GetObject(class:="Word.Application") Set

Use a variable to select an ActiveX control Checkbox by name (in Word from Excel)?

末鹿安然 提交于 2019-12-11 01:38:47
问题 What is wrong with this line of code? WordDoc.CheckBoxNum.Value = CheckBoxVal To be clear, I am working with an ActiveX control "Checkbox". I have the values (true/false) and checkbox names saved in an Excel file. The code opens my word document and automatically loops through the checkboxes, setting their values. The fact I am controlling word from Excel may change my objects? If they were Form Field... This works-- CheckBoxNum = "Check1" CheckBoxVal = "True" WordDoc.FormFields(CheckBoxNum)

Word Macro to find and replace all in word document with textboxes

一世执手 提交于 2019-12-11 01:34:40
问题 I need to write a VBA Word macro that will do a find and replace to change all occurrences of text in one font to another font. The code I have (listed below) does this but in ignores all the text in text boxes in the document. How do I either modify this macro to search all text both inside and outside textboxes in the document (headers and footers would be a plus but not absolutely necessary) or do it a different way in a macro. This macro is part of a larger macro that processes tens of

VBA Error 4198 “Runtime Error” With Paste

≡放荡痞女 提交于 2019-12-11 00:37:03
问题 I have been trying to write a word VBA script that uses a screenshot (already copied to the clipboard) and pastes it into a word document to be formatted and saved. The program works great on my computer at work, but when I distributed it to others, it failed to work on about 25% of the computers. The error that I received was "4198 Runtime Error". I have searched for similar problems that other people have had, but I am still at a loss. All of the computers in the office run the same version

looping a find and delete row macro

て烟熏妆下的殇ゞ 提交于 2019-12-11 00:32:39
问题 Please forgive the hand-holding that I'm sure I'm going to need on this question. I have very little experience with visual basic. Here's what I'm trying to do: I have a large table in Word 2011 (Mac), and I need to find a certain string within the table and delete the row that contains it. Okay, no problem to do that by recording a macro. However, I'd like to have the macro find all instances and delete the rows all at once rather than having to run the macro over and over (besides which,

Saving and closing office programs (word, excel, access, outlook) with VBS for backups

断了今生、忘了曾经 提交于 2019-12-10 23:46:22
问题 After spending a fair amount of time looking around, I'm coming up a little stumped, as this is (I'm sure) a pretty common problem. I run nightly backups of all our office machines, but Outlooks PST files often prevents this form successful completion. I found the solution to this for outlook, but other MS Office apps tend to block backups from successful completion as well. I've figured out how to save and close Outlook, Word, and Excel. Access I have a solution for, but would like to close

Creating a RegEx to find a sentence with a parenthetical acronym (VBasic Word)

て烟熏妆下的殇ゞ 提交于 2019-12-10 23:19:27
问题 I'm writing a script that scrubs a document to find acronyms in the format (USA). As a processing tool I need to grab the entire sentence in which that parenthetical acronym appears. Right now my code for finding the acronym is: With oRange.Find .Text = "\([A-Z]{2,}\)" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = True .MatchWildcards = True Combining this with a Do While .Execute I can comb the doc and find the acronyms, then using a string function I take the acronym out

VBA Word - changing decimal separator

拜拜、爱过 提交于 2019-12-10 21:43:41
问题 Some people around me using national localization in windows/office. Unfortunately this leads to situation where my macros fail to do simple math as they using comma for decimal position and the pov-ray files, that I editing, use comma only for list separator and point for decimal one. I know that in Excel one can override system decimal separator using With Application. .DecimalSeparator = "." .ThousandsSeparator = "," .UseSystemSeparators = False End With There is however no such property