word-vba

ActiveX textbox value

谁说胖子不能爱 提交于 2019-12-30 09:51:43
问题 How do I get the value of a textbox in Word? I know in excel this is the right syntax: ActiveSheet.Shapes(x).Name . I thought in word this would be the right syntax ActiveDocument.Shapes(x).Name , but this doesn't seems to work. With this piece of code I also couldn't find a textbox: For i = 1 To ActiveDocument.Shapes.Count MsgBox ActiveDocument.Shapes(i).Name Next i 回答1: To get the value of a standard textbox , use this: ActiveDocument.Shapes(1).TextFrame.TextRange.Text To get the value of

copy formatted text into access using vba

爷,独闯天下 提交于 2019-12-30 08:33:31
问题 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

How to run a macro in Word before save?

痴心易碎 提交于 2019-12-29 07:07:06
问题 How to make Microsoft Word to run a VBA macro every time before any document is saved? Could it be done without adding macros into the document itself? 回答1: You can subscribe to application events in Document_Open by using WithEvents variable and conventional method names ( VariableName_EventName ). Works in templates as well. You can put this code into ThisDocument object, or make a separate class module as described here. Private WithEvents App As Word.Application Private Sub Document_Open(

Macro to export MS Word tables to Excel sheets

╄→гoц情女王★ 提交于 2019-12-28 03:30:46
问题 I have a word document with many tables. Does anyone know how to write a macro to export such tables to different Excel sheets? 回答1: 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

Accept Formatting Changes in Word Headers, Footers and Main Document

落爺英雄遲暮 提交于 2019-12-25 19:08:21
问题 I'm using the following VBA code to accept all formatting changes in a document. Which lines would I need to add in order to accept the changes in the Header and Footer as well? ActiveDocument.ShowRevisions = True ActiveDocument.ActiveWindow.View.ShowFormatChanges = True ActiveDocument.ActiveWindow.View.ShowComments = False ActiveDocument.ActiveWindow.View.ShowInsertionsAndDeletions = False ActiveDocument.ActiveWindow.View.ShowInkAnnotations = False ActiveDocument.AcceptAllRevisionsShown

Word Userform won't open in second, currently active document after opened/unloaded in first document

江枫思渺然 提交于 2019-12-25 18:36:40
问题 The headline really says it all, but here's my situation: I have a userform set up to collect user input, then uses that input in a macro and executes it. That, in itself, works exactly like I want it to. The problem comes when more than one document is open. To illustrate: I have two documents, 'doc a' and 'doc b'. I open both documents, then select 'doc a', open the userform using a show userform macro, input my data, and hit either 'Okay' or 'Cancel' (both of which are set to unload the

Microsoft Word VBA - Select table if cell contains specified string

大城市里の小女人 提交于 2019-12-25 16:55:29
问题 I'm having trouble creating a Microsoft-Word macro. Here's the macro that I'm working on. It successfully selects each individual table in a word document. Sub FindSpecificTables() Selection.WholeStory Dim iResponse As Integer Dim tTable As Table 'If any tables exist, loop through each table in collection. For Each tTable In ActiveDocument.Tables tTable.Select If response = vbNo Then Exit For 'User chose to leave search. Next MsgBox prompt:="Search Complete.", buttons:=vbInformation End Sub

Microsoft Word VBA - Select table if cell contains specified string

梦想的初衷 提交于 2019-12-25 16:55:03
问题 I'm having trouble creating a Microsoft-Word macro. Here's the macro that I'm working on. It successfully selects each individual table in a word document. Sub FindSpecificTables() Selection.WholeStory Dim iResponse As Integer Dim tTable As Table 'If any tables exist, loop through each table in collection. For Each tTable In ActiveDocument.Tables tTable.Select If response = vbNo Then Exit For 'User chose to leave search. Next MsgBox prompt:="Search Complete.", buttons:=vbInformation End Sub

I need to create a stopping condition for my program

拟墨画扇 提交于 2019-12-25 14:29:16
问题 I have a program that highlights all the words between a start and end point and loops through the extract to find the same conditions. Program works well, except it does not stop looping. I have to break the running program to stop it. can someone please help me write up a condition that says if the end is reached and the start and end condition don't to exist, to stop the program. Sub SomeSub1() Dim StartWord As String, EndWord As String Dim Find1stRange As range, FindEndRange As range Dim

Word VBA Find/Replace Issue

心已入冬 提交于 2019-12-25 08:00:39
问题 Using the VBA Find and Replace in Word i have the issue that if i am trying to replace all instances of "John(space)Smith" for example, with "John(non-breaking space)Smith", the Find Replace function replaces all "John(space)Smith" as well as all "John(non-breaking space)Smith" with "John(non-breaking space)Smith". Before i am using this and leaving track changes i don't really want it to replace it with itself. I have tried using Chr(32) to only select the space but still to no avail. (I