word-vba

MS Word VBA - Finding a word and changing its style

心已入冬 提交于 2020-01-03 17:12:09
问题 I'm trying to find all instances of key words in a MS Word document and change their style. The key words are stored within an array and I want to change the style of the particular word only. Ideally this would happen as I type but that is not crucial. Attempt 1 - Based on recording a macro and changing the search term Sub Woohoo() Dim mykeywords mykeywords= Array("word1","word2","word3") For myword= LBound(mykeywords) To UBound(mykeywords) Selection.Find.ClearFormatting Selection.Find

Running a macro before printing a word document

╄→гoц情女王★ 提交于 2020-01-03 13:04:09
问题 I have a macro in word 2010, that adds a footer to documents when you print them (i.e. after you click the "final" print button, in the print preview screen). Currently, in order to foot the document, the user needs to run the macro first, and only after running it, when they print the document, the footer is added. I would like to automate the part of running the macro, so that selecting a printing option (Ctrl+P / File>Print) would run the macro automatically and open the print preview

How to use Word 2013 parameter in VBA template and compile in Word 2010

扶醉桌前 提交于 2020-01-03 06:05:13
问题 I'm writing code for a template that needs to work in many Word versions (2003 through 2013, minus 2008). I've accepted that it won't compile in all of those versions. I mostly write my code in Word 2010. Up until now I've always been able to get it to compile in 2010, but now I've hit a stumbling block. I need to add a comment to a document with a specific user name that I define. I do this by holding the current username and userinitials in variables, setting them to what I want, adding my

Microsoft Word 2013 macro save file name from form content

我只是一个虾纸丫 提交于 2020-01-03 06:01:07
问题 I'm trying to write a macro that will save a Microsoft Word 2013 document with a specific filename. I have created a word form that a client fills out. I would like to create a macro that automatically saves the document with the name of one of the fields that the client fills out in the form. Example: below are fillable content fields. client reference: A1B2-345 date: August 17, 2015 type: metadata I would like to save the file as: A1B2-345_17082015_metadata.DOCX I'm fairly new to

How to delete Text between start and end vba word

淺唱寂寞╮ 提交于 2020-01-03 05:26:10
问题 How can one go about deleting text between a start word and an end word. I have a huge text extract of about 1 million plus words and I want create a VBA Script which will delete all the unwanted text. Fortunately I have the key words to look for and delete all the text after those key words up to a specific end point which I would like to enter. I need a program that can find these key words and dedicate them as the start words and then an end word as the end position and to delete all the

Creating Word or XML document with VBA

北城以北 提交于 2020-01-03 03:50:20
问题 I need to create documents, (~150 reports, letters) mostly from pre-existing snippets and local databases, with VBA, in Word 2003. I then need to change specific parts of those snippets, such as dates, phrases, user information, &c. There are also, obviously, some bits that I will generate in my program. Currently, this same task is done (sort of) by some hideous legacy VBA. (Nested IFs and FORs, and over 200 textboxes all called TextBox#) It gets the job done SOMETIMES, and does so by

Preserve formatting of Word table in Excel VBA

落花浮王杯 提交于 2020-01-03 03:05:27
问题 From another discussion, I was able to find this macro that imports a table from Word into Excel. It works great but how I can make it keep the formatting of the Word table? I have tried a few ways but can't quite get it working. Also is there a way to do more files at once and not just 1 at a time? Option Explicit Sub ImportWordTable() Dim wdDoc As Object Dim wdFileName As Variant Dim tableNo As Integer 'table number in Word Dim iRow As Long 'row index in Excel Dim iCol As Integer 'column

Save the active open document as pdf file

↘锁芯ラ 提交于 2020-01-03 00:54:12
问题 I have the below code that copy range cell values from excel and paste as picture in a new word document. I want to save the active document as pdf file with name of file as value in cell "A2". If you can help me in adding the same in the below code it would be a great help. Sub Picture() Dim objWord, objDoc As Object ActiveWindow.View = xlNormalView Range("A2:K25").Select Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture Set objWord = CreateObject("Word.Application") Set objDoc =

Send BACKSPACE keystroke in Word VBA

陌路散爱 提交于 2020-01-02 08:28:10
问题 I have made some code in Word VBA and at the end I need 1 backspace keytroke. How is this achievable? 回答1: The simple way to send a backspace (but not the most robust solution) : SendKeys ("{BACKSPACE}") A safer way to do this : Selection.MoveLeft Extend:=wdExtend Selection.Delete If something is already selected, and you want to delete just the last character, preface the above by : Selection.Collapse wdCollapseEnd To go to the start of the current page : ActiveDocument.GoTo(wdGoToPage,

What are the benefits of MS Word content controls?

一个人想着一个人 提交于 2020-01-02 07:14:32
问题 Office 2007 brings a new goodie called as 'content controls'. I need to evaluate this to see if this serves as a solution for a problem under research. Due to paucity of time and my general disdain for Office-interop-pains, can someone summarize the benefits? Is it possible to define custom content controls? where do all the word programmers (if there are any) hang out :) ? RTFMsdn links also welcome. So far I see (from some screencasts) that its now possible to define - template word docs