word-vba

Using vba to copy the contents of a word document into another word document

我的梦境 提交于 2019-11-27 22:22:09
问题 I haven't used VB for years, so please forgive me if this turns out to be obvious. I'm trying to write a word vba macro for use in a template which will display a userform and then import the contents of fileA.docx, fileB.docx, or fileC.docx depending on the userform. (After that I'm going to use bookmarks to fill in some form data, I don't know if that's relevant). Files A, B, and C will contain text with some basic formatting such as lists, but nothing fancy. The solutions I've seen online

Creating a self install macro?

无人久伴 提交于 2019-11-27 17:02:51
问题 Hello I create many macros for my co workers. The current method I have for distributing to another computer is going into the vba editor and importing. I would really like to make a kind of "installer" for macros that would allow the user to install a new macro without having to go into the editor. I'm not sure this is even possible but any ideas are welcome! Thanks! 回答1: You need to enable Microsoft Scripting Runtime library under references. (VBE -> Tools -> References. Check the box.)

Repeating Microsoft Word VBA until no search results found

*爱你&永不变心* 提交于 2019-11-27 15:07:51
I've created a MS Word macro that searches for certain text (indicated by markup codes), cuts the text and inserts it into a new footnote, and then deletes the markup codes from the footnote. Now I want the macro to repeat until it doesn't find any more markup codes in the text. Here's the macro below Sub SearchFN() 'find a footnote Selection.Find.ClearFormatting With Selection.Find .Text = "&&FB:*&&FE" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchKashida = False .MatchDiacritics = False .MatchAlefHamza = False

Macro to export MS Word tables to Excel sheets

旧街凉风 提交于 2019-11-27 11:29:28
I have a word document with many tables. Does anyone know how to write a macro to export such tables to different Excel sheets? Bnjmn Answer taken from: http://www.mrexcel.com/forum/showthread.php?t=36875 Here is some code that reads a table from Word into the active worksheet of Excel. It prompts you for the word document as well as the table number if Word contains more than one table. 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 index in Excel wdFileName =

Extract Data from Word Document to an Excel SpreadSheet

北城余情 提交于 2019-11-27 09:43:08
I have a requirement to extract a value from a word document on a daily basis and write it to an excel workbook. I currently do this manually and it is border line regarding the most efficient method for me Using Excel file create a vba script and add any word document references. 2 Using the word navigate to the table “9. STOCKS...” (extracted example below – Appendix A) and read the Diesel (ltrs) daily usage highlighted in red. 3.Write this value to a spreadsheet cell. The date for this value is also key but it held in another part of the word document (Appendix B). Dates are also in the

word vba: webbrowser not navigating for ReadyState to check

风流意气都作罢 提交于 2019-11-27 08:43:56
问题 I am trying to extract links from webpages, but it seems webbrowser does not navigate, so I get infinite loop at webbrowser1.readstate <> readystate_complete... HOWEVER, if make a breakpoint at webbrowser1.readstate <> readystate_complete, the webbrowser navigates successfully in the userform, and code works.... Any ideas? Thanks Do Until n = num WebBrowser1.Navigate URL Do While WebBrowser1.readyState <> READYSTATE_COMPLETE Loop If WebBrowser1.readyState = READYSTATE_COMPLETE Then 'code end

Capturing keydown event of MS Word

☆樱花仙子☆ 提交于 2019-11-27 08:38:54
问题 I want to capture the backspace event, just do the backspace's action, then add other action, but I am not sure the backspace's original action:Selection. Delete , -1 ? Sub AddKeyBinding() With Application ' \\ Do customization in THIS document .CustomizationContext = ThisDocument ' \\ Add keybinding to this document Shorcut: Backspace .KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyBackspace), _ KeyCategory:=wdKeyCategoryCommand, Command:="TestKeybinding" End With End Sub ' \\ Test sub for

Copy Text from Range in Excel into Word Document

柔情痞子 提交于 2019-11-27 07:29:03
问题 how do you: 1) copy text from a range in an Excel Document. 2) Open a Word Document. 3) inserts the text into a specific part of the word document. regards Kojo Edit: here is the approach Dim wrdApp As Word.Application Dim wrdDoc As Word.Document Dim j As Integer Set wrdApp = CreateObject("Word.Application") wrdApp.Visible = True Set wrdDoc = wrdApp.Documents.Open("C:\Files\DailyStrategy.doc") With wrdDoc If wrdDoc.Bookmarks.Exists("MarketCommentry") Then wrdDoc.Bookmarks("MarketCommentry")

How to Clear Office Clipboard with VBA

喜欢而已 提交于 2019-11-27 07:08:49
问题 How would you clear the Microsoft Office Clipboard using VBA, specifically Word VBA? I am copying a lot of data at time into the clipboard and don't want excessive data kept in the Clipboard. 回答1: Would a simple Application.CutCopyMode = False work for your situation, or is this option not viable? 回答2: Saw this on another post, and I have tested it with Word VBA. 'Clearing the Office Clipboard Dim oData As New DataObject 'object to use the clipboard oData.SetText text:=Empty 'Clear oData

vba WScript.Shell run .exe file with parameter

血红的双手。 提交于 2019-11-26 22:06:55
问题 I am running a VBA macro from Word 2013. I'm trying to run an executable file which requires an argument/parameter of a filename. For example, c:\myfilefilter.exe filetobefiltered.htm I would like to use Shell Run because I want the VBA code to wait until the executable is finished running before resuming the VBA code. The last three lines in the code below are examples of some of the syntax I have tried which do not work. I think the problem is the space between the executable program and