Word VBA / Macro Problem With Print && Browser (Word 2000)
I am trying to use a macro inside the AutoOpen() event of a Word doc so that when the Word doc is opened inside IE, it will print the Word doc then close both the Word doc and the IE window. For some reason, VBA loses its reference to the doc object and IE Application object after the PrintOut line is executed. I have tried things like:
MyWord.Visible = False
Dim MyWord As Object
Set MyWord = GetObject(, "Word.Application")
Dim IE As Object
Dim IEDoc As Object
Set IE = GetObject(, "InternetExplorer.Application")
Set IEDoc = MyWord.ActiveDocument
But whatever I try, the Word doc prints, then throws a 4605 error about the method or property not being available because the document is in another app. Any ideas?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
WORD 2000 Macro Passwords
Thanks for granting me access to your site.
I have inherited a bunch of Office 2000 documents from the guy who was fired to make way for me to be hired.
Is there an industry standard software package that will allow me to remove the macro passwords he placed on all of our corporate document templates? We're unable to modify anything about the macros, and he's unwilling to pass along the passwords.
I guess I could recreate everything this guy did, but what a pain in the neck that could turn out to be.
Thanks for a great site, I hope to be a long standing contributor.
Run Macro On Save Word 2000
Hey folks, I need to run a macro On File_Save or File_Send To in Word...
Is there any way to invoke a macro on these events or am I destined to fail?
This is to run a protection script on save of a document...
Thanks in advance...
Word Print Macro
I want to be able to print from a different tray in MS Word 2000 using a macro but i haven't been able to do so and I decided to come here to see If I can get some answers. here's the link to where i previously posted, but I didn't get too many replies. Hopefully i will get more here.
Calling A Macro In Another Template In Word 2000
I am trying to call a macro in a template that I attach a run-time and the error I get keeps telling me that it is unable to run the specified macro...the code is as follows
' attach the new Signature template to override styles
.UpdateStylesOnOpen = True
.AttachedTemplate = _
"C:WINNTProfiles" + Environ("USERNAME") + "Application DataMicrosoftTemplatesSignature.dot"
Quote:THE ERROR OCCURS HERE...Should I be using another method?
' auto-run the conversion to the new look after the signature template is attached
Thanks in advance...
"Do or do not, there is no try."
Word 2000 - Macro - Trap Events
I'm pretty sure that there is a solution for my question. If any one knows please let me know.
I just want to TRAP a few events in Word 2000, like if the position of my cursor in the Word is moved, an event should get fired through which I will call a macro. I know that it is possible, because I've seen it in a template, but the code there is stored in a DLL, and hence, I was unable to see how it is done.
Macro: Close Word After Print
Is there a way I can close word automatically after a file prints?
here is the macro:
with this it prompts and says if word exits the print will stop. is there an .isbusy command or something similar to that..so that i can have the application wait until printing completes and then exit?
Macro To Print To Adobe PDF (Word)
Hello again. Once again I have an issue with a macro naming and placing files in ways that I don't like. I recorded an extremely simple macro to "print" word documents to Adobe .PDF files, and it does do its job properly as far as the actual conversion goes (there's not a whole lot to screw up there, after all). However, I'd like to be able to include something in the macro's code that will give the PDF file the same filename as the original document (and also replace the .doc extension with .pdf) and place it in a specific location.
The code generated by the "record new macro" feature:
' Macro4 Macro
' Macro recorded 8/3/05 by <My name>
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
A couple of linked pictures for clarification:
This just shows the dialouge box that shows up when printing to the PDF Maker.
This shows the save dialouge which appears after selecting the print button from the previous dialouge. The macro doesn't recognize the existence of this dialouge, so it automatically gives the file a pointlessly long filename and saves it automatically to the desktop.
So basically, I'd like to know if it's possible to include something in the macro's code which will give the converted file the name of the active document (minus the .doc, plus .pdf) and will save it in a specific location. I'd appreciate any input on this, and I'll try to provide further clarification if necessary.
Thanks in advance.
I Need Macro To Resize Too Wide Graphics In Word 2000
My question is this. I write user manuals that start out as .rtf files that I export from ForeHelp, a Windows help authoring tool. I have tons of screen shots in this doc, many of which are wider than 6.5 inches. This means they don't fit within the margins when it comes into Word. Is there some way I can make the graphics fit inside the margin when I open it? Or perhaps a search macro that selects the oversized graphic would help?
I tried to write a macro that would search for a graphic (^g in the search and replace thingy) but that lands on graphic bullets too that don't need to be resized. Some of the graphics that are too wide should not be replaced automatically (because the height gets screwed up and isn't proportional anymore), but should be fixed be a different method, so I would want to mark these with a style code or something I can search for later. Currently, I have to page down through hundreds of pages (up to 800) to find the graphics that need to be resized. Ugh! Then I click on a custom macro on my toolbar that resizes it. This macro works fine, but I have to find and then select the graphic before it works.
Is there some way I can search for only graphics that are wider than 6.5 inches and perhaps taller than a certain height? I don't know how to write custom macros but I can use the recorder just fine. How would I record something like that? I do know how to get into the VB Macro editor and insert While/Wend statements to get it to repeat till the end, but that's all the coding I know.
Betty Gravlin, Software Technical Writer
Make Word Document Active And Print From Excel Macro
I have an excel spreadsheet with multiple hyperlinks to MS Word files. I know how to open the files using the following code:
ActiveWindow.View = xlNormalView
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
I need to know how to make the Word file the active window and then print it to the default printer in VB. I also need to know how to handle any error or warning messages. ie., when a box pops up to tell me the file should be opened as read only.
Urgent- Word 2000 And Word 2003 Problems Using Vb6 Error Number 5941
I have Developed a VB6 Application which adds the data from DB
to MS Word 2003 Document (With Tables and other Details).
The Program Works Fine with Word 2003
But in Word 2000 Program Generates an Error "Requested Member of Collection Does not exists"
Error Number 5941.
Does there is any Functional Difference with Word 2000 and Word 2003 ? i.e. with Objects of Word ?
Code Lines :-
oWorAapp.ActiveDocument.Tables(TableNumber).Cell(Row:=RowNumber, Column:=ColNumber).Range.InsertBefore Text:=TextToAdd
Program Error is on above mentioned Line, Parameters values are :-->
RowNumber = 7
ColNumber = 3
TableNumber = 50
TextToAdd = "Sample Data"
If I check the Table Count then Count is 60, Row Count is 10 and Column Count is 10 (From methods of WordApp Object
Please note that this works Fine in Word 2003. If user tries to execute this exe in word 2000 then error is raised
I am Very much Thankful for all the reply's
Edited by - SmartCodar on 9/26/2006 1:24:41 AM
Calling Word SaveAs Dialog In Word 2000 & Higher
In my VB app, I open a Word document in print preview. When the user clicks the Save button, I want to bring up a SaveAs dialog. Since our users may have Office 2000, XP or 2003, I had to use late binding when declaring the object:
Public msword As Object
Here's my Save button code:
Private Sub cmdSave_Click()
If msword Is Nothing Then
Set msword = CreateObject("Word.Application")
.Name = "tstcat.doc"
This works fine for PC's running Office XP (haven't tried it with Office 2003). For Office 2000, however, when you click the Save button, you go into some kind of nasty loop (title bar flashes), and you have to kill the app in Task Manager.
Is there a way to make this work for all three versions of Word?
Word 2000 Macros In Word 2002 && Less Functionality?
This is a two-part question.
I've just upgraded one computer to Windows XP/Office XP from Windows 2000/Office 2000. I've been recording and editing macros since way back when Word Basic was around, although I've never needed to write my own code from scratch - until now.
I have a multitude of macros that were created (recorded) & then edited further in Word 2000 that, while they still run in Word 2002, I can no longer edit them when I need to. I get a Project Locked dialog box that says "Project is unviewable". I have another computer that still has the Windows 2000/Office 2000 config, but I cannot open them there either. Is there a solution or workaround to this?
OK, next question:
I OCR & clean up/edit long documents that have been scanned. One of the most useful functions of Word's macro capability (for my purposes, anyway) has been the ability to record finding & replacing formatted text. Now, when trying to record new macros, I'm finding that Word no longer records the formatting in either Find or Replace. The command runs correctly while I'm recording the action, but when I attempt to run the macro I've recorded, I've found that it didn't retain the formatting variables, so it deletes the text it finds instead of formatting it, or doesn't find the formatted text.
This in itself wouldn't be such a problem if I could edit the macros I've already got; I'd just copy & edit the code appropriately! Is this a drawback of the new version of Visual Basic, or is it just me?
Word - MailMerge With VB, Word 2000 And An Access 97 Database
I have written a programme in VB that must do the following things:
- Open a Word template (Works fine)
- Open a datasource (Works fine) to a Access 97 database. (I'm not allowed to change this, so i'll have to put up with that.)
How can i prevent that Access is being opened while running the programme? I only want to show the template which uses the Access 97 database. When i tested this with Word XP it worked fine and DID not open Access, but when i tried this with Word 2000 then Access did start up. I have to prevent this because i'm not allowed to supply Access.
Does anyone have an answer to this one??
Word 2000: Underline A Word Underlines The Space Between
I have the following code to select a Range object and apply underlining to
a particular word within the range. For some reason, Word is not only
underlining the word, but also the space after the word that is between 2 words. Does anyone know how I
can get it to only underline the word and not the space after it?
Dim rRange As Range
Set rRange = ActiveDocument.Bookmarks("MyRange").Range
' Underline the following word within the range
.Words(53).Font.Underline = wdUnderlineSingle
Extract Each Word From A String And Print One Word Per Line.
I have a textbox that contains a string(can be any number of words).
How do i extract each word from the string and
print one word per line onto the form? e.g.
Hi can someone please help me
Print to form:
Excel Closes, But Word Doesn't! And Word Won't Print!
My code needs to open Excel, populate a table with data, mail-merge that table with a Word document, and finally print the merged documents. I have two problems:
1) As the program finishes, Excel closes and is removed from the Task Manager's Processes list, but Word is not removed. I've tried the .Quit method for both (even accounting for Word's use of parameters), but "WINWORD.EXE" remains on the list even after "EXCEL.EXE" is removed. I also set my objects to Nothing in Class_Terminate, but still no luck - and putting the .Close/.Quit procedures under Class_Terminate gave me an error. I know Excel is working because the program is saving my .xls files, but I'm not sure about Word. Which leads to...
2) Obviously I'm only opening Word to merge the file - the text of the document itself never changes so it doesn't need to be saved, just linked to the data source (the Excel table just created). But I can't get Word to print! I set the .ActivePrinter property and used .PrintOut but no luck. What do I have wrong here? Thanks for any insight.
Owen, Little and Assoc., Inc.
P.S. This code runs from within ArcMap, a digital-mapping software package. Hence all of the "ICommand"s and "IMap"s and such, the use of "ISelectionSet" to populate the Excel table, etc. All of the code pertaining to ArcMap works fine - it's mostly just the part at the end of the code relating to Word where there must be something I'm doing wrong.
Private m_pApp As IApplication
Private m_pMxDoc As IMxDocument
Private m_pMap As IMap
Private m_pExt As IExtension
Private m_pFeature As IFeature
Private m_pFeatureLayer As IFeatureLayer
Private m_pFeatureCursor As IFeatureCursor
Private m_pFeatureSelection As IFeatureSelection
Private m_pSelectionSet As ISelectionSet
Private m_pFields As IFields
Private m_pField As IField
Private m_pRow As IRow
Private m_pCursor As ICursor
Private m_pQBLayer As IQueryByLayer
Private m_pBitmap As IPictureDisp
Private m_pAppExcel As New Excel.Application
Private m_pWorkbook As Excel.Workbook
Private m_pWorksheet As Excel.Worksheet
Private m_pAppWord As New Word.Application
Private m_pDocument As New Word.Document
Private m_pMailMerge As MailMerge
Private Sub Class_Initialize()
Set m_pBitmap = LoadResPicture(101, vbResBitmap) 'Button icon
Private Sub Class_Terminate()
Set m_pApp = Nothing
Set m_pMxDoc = Nothing
Set m_pMap = Nothing
Set m_pExt = Nothing
Set m_pFeature = Nothing
Set m_pFeatureLayer = Nothing
Set m_pFeatureCursor = Nothing
Set m_pFeatureSelection = Nothing
Set m_pSelectionSet = Nothing
Set m_pFields = Nothing
Set m_pField = Nothing
Set m_pRow = Nothing
Set m_pCursor = Nothing
Set m_pQBLayer = Nothing
Set m_pBitmap = Nothing
Set m_pAppExcel = Nothing
Set m_pWorkbook = Nothing
Set m_pWorksheet = Nothing
Set m_pAppWord = Nothing
Set m_pDocument = Nothing
Set m_pMailMerge = Nothing
Private Property Get ICommand_Bitmap() As esriSystem.OLE_HANDLE
ICommand_Bitmap = m_pBitmap
Private Property Get ICommand_Caption() As String
ICommand_Caption = "200' List"
Private Property Get ICommand_Category() As String
ICommand_Category = "Extending ArcObjects"
Private Property Get ICommand_Checked() As Boolean
ICommand_Checked = False
Private Property Get ICommand_Enabled() As Boolean
ICommand_Enabled = True
Private Property Get ICommand_HelpContextID() As Long
Private Property Get ICommand_HelpFile() As String
Private Property Get ICommand_Message() As String
ICommand_Message = "Creates a 200' list for selected property and generates an Excel file (for mail merge)"
Private Property Get ICommand_Name() As String
ICommand_Name = "ExtendingArcObjects_200FootList"
Private Property Get ICommand_Tooltip() As String
ICommand_Tooltip = "Create a 200' list"
Private Sub ICommand_OnCreate(ByVal hook As Object)
Dim a As New UID
Set m_pApp = hook
a.Value = "CmdToolbarExt.clsLaunchExtension"
Set m_pExt = m_pApp.FindExtensionByName("200FootListExtension")
Private Sub ICommand_OnClick() ''MAIN BUTTON
Dim a As Long 'Field (i.e. column) value
Dim b As Long 'b-d: counters
Dim c As Long
Dim d As Long
Dim lMaxSize(8) As Long 'Width of each field
Dim sValue As String 'Current record's value (string)
Dim lHolder As Long 'Temp. field width value
Dim sFieldName(8) As String
Dim sBlock As String
Dim sLot As String
Dim sFirstRecord As String 'Holds IDNum of 1st selected record
Dim sFileName As String
sFieldName(0) = "IDNum"
sFieldName(1) = "Block"
sFieldName(2) = "Lot"
sFieldName(3) = "FULLNAME"
sFieldName(4) = "ADDRESS"
sFieldName(5) = "CITY"
sFieldName(6) = "STATE"
sFieldName(7) = "ZIP"
sFieldName(8) = "PROPLOC"
Set m_pMxDoc = m_pApp.Document
Set m_pMap = m_pMxDoc.FocusMap
Set m_pFeatureLayer = m_pMxDoc.FocusMap.Layer(0) '!!Change to reflect name
Set m_pFeatureSelection = m_pFeatureLayer ' of parcel layer!!
Set m_pCursor = m_pFeatureLayer.Search(Nothing, False)
'Create Excel file name
Call m_pFeatureSelection.SelectionSet.Search(Nothing, False, m_pFeatureCursor)
Set m_pFeature = m_pFeatureCursor.NextFeature
sFirstRecord = "Block" & m_pFeature.Value(m_pFeature.Fields.FindField("Block")) & "Lot" & _
Set m_pQBLayer = New QueryByLayer
With m_pQBLayer 'Select all parcels within 200 feet
Set .ByLayer = m_pFeatureLayer ' of the selected parcel
Set .FromLayer = m_pFeatureLayer
.BufferDistance = 200
.BufferUnits = esriFeet
.ResultType = esriSelectionResultAdd
.LayerSelectionMethod = esriLayerSelectWithinADistance
.UseSelectedFeatures = True
Set m_pFeatureSelection.SelectionSet = .Select
Set m_pSelectionSet = m_pFeatureSelection.SelectionSet
Call m_pSelectionSet.Search(Nothing, False, m_pCursor)
Set m_pFields = m_pCursor.Fields
Set m_pRow = m_pCursor.NextRow
'*******************************mostly ArcMap code above this line************
'*******************************mostly VBA code below this line***************
Set m_pAppExcel = CreateObject("excel.application") 'Create Excel instance
Set m_pWorkbook = m_pAppExcel.Workbooks.Add 'Create workbook/worksheet
Set m_pWorksheet = m_pWorkbook.Sheets.Add(After:=m_pWorkbook.Sheets(m_pWorkbook.Sheets.Count))
Cells(1, 1).Value = "IDNumber" 'Field names
Cells(1, 2).Value = "Block"
Cells(1, 3).Value = "Lot"
Cells(1, 4).Value = "Name"
Cells(1, 5).Value = "Address"
Cells(1, 6).Value = "City"
Cells(1, 7).Value = "State"
Cells(1, 8).Value = "ZIP"
Cells(1, 9).Value = "Property Loc."
m_pAppExcel.DisplayAlerts = False 'Kill first three sheets
m_pAppExcel.DisplayAlerts = True
m_pWorksheet.Name = "200 Foot List"
m_pWorksheet.Rows(1).Font.Bold = True
c = 1
d = 1
Do While Not m_pRow Is Nothing 'Grab values from selection set
c = c + 1
For b = 0 To 8
a = m_pFields.FindField(sFieldName(b))
m_pWorksheet.Cells(c, d).Value = m_pRow.Value(a) 'Write value to record
sValue = m_pRow.Value(a)
If c = 2 Then 'Find the longest entry in each field
lMaxSize(b) = Len(sValue)
lHolder = Len(sValue)
If lHolder > lMaxSize(b) Then
lMaxSize(b) = lHolder
d = d + 1
Set m_pRow = m_pCursor.NextRow
d = 1
If lMaxSize(0) < 10 Then lMaxSize(0) = 10 'Minimum widths for fields
If lMaxSize(1) < 6 Then lMaxSize(1) = 6
If lMaxSize(2) < 4 Then lMaxSize(2) = 4
If lMaxSize(3) < 6 Then lMaxSize(3) = 6
If lMaxSize(4) < 8 Then lMaxSize(4) = 8
If lMaxSize(5) < 4 Then lMaxSize(5) = 4
If lMaxSize(7) < 6 Then lMaxSize(7) = 6
If lMaxSize(8) < 13 Then lMaxSize(8) = 13
m_pWorksheet.Columns("A").ColumnWidth = lMaxSize(0) 'Set field widths
m_pWorksheet.Columns("B").ColumnWidth = lMaxSize(1)
m_pWorksheet.Columns("C").ColumnWidth = lMaxSize(2)
m_pWorksheet.Columns("D").ColumnWidth = lMaxSize(3)
m_pWorksheet.Columns("E").ColumnWidth = lMaxSize(4)
m_pWorksheet.Columns("F").ColumnWidth = lMaxSize(5)
m_pWorksheet.Columns("G").ColumnWidth = lMaxSize(6)
m_pWorksheet.Columns("H").ColumnWidth = lMaxSize(7)
m_pWorksheet.Columns("I").ColumnWidth = lMaxSize(8)
sFileName = "C:200FootList_" & sFirstRecord & ".xls"
Call m_pWorksheet.SaveAs(sFileName) 'Save Excel file (for this instance)
m_pAppExcel.DisplayAlerts = False
Call m_pWorksheet.SaveAs("C:200FootListMerger.xls") 'Save dummy copy of Excel file
m_pAppExcel.DisplayAlerts = True ' for mail merge (always overwrites)
Call m_pAppExcel.Application.Quit 'Quit Excel
Set m_pAppWord = CreateObject("word.application") 'Create Word instance
m_pAppWord.ActivePrinter = "\DellserverSHARP407 on Ne04:"
'Open document for mail merge
Set m_pDocument = m_pAppWord.Documents.Open("C:MailMerge.doc")
m_pDocument.MailMerge.Destination = wdSendToNewDocument
Call m_pDocument.PrintOut 'Print letters
Call m_pAppWord.Application.Quit(False) 'Quit Word
Why Does This Work In Word 2000 And Not Word 1997??
Thanks in advance for reading...
And thanks for all the help you guys gave when
I asked about something like this before...
I was having a problem with wildcards, and I finally got it to
work, however this DOES NOT work in word 97...
This string I have finds filenames with variable suffixes.
for example, the string can be:
(The first part stays the same, and the suffix can change)
Here is how I reference this in word 2000, and it works great
search_file_name = file_name + "*.jpg"
the "*.jpg" accounts for any sequence of 001, 002 etc,
but this does not work in word 97
what can I change???
Word 2000 To Word 2002 Problems
I have having some issues going from Word 2000 to Word 2002, for some reason my code is throwing up an:
"This command is not available because no docuement is open"
Here is the code (works fine in word 2000, well some bugs but no errors):
Public Function Printsign(sign_name As String)
Dim objWdApp As Word.Application
Dim objWdDoc As Word.Document
Dim objWdRange As Word.Range
Set objWdApp = New Word.Application
Set objWdDoc = objWdApp.Documents.Open(FileName:="C:SIGN.doc")
objWdApp.Visible = True
Set objWdRange = objWdDoc.Content
.Text = "text"
.Replacement.Text = sign_name
Dim strText1 As String
Dim strText2 As String
Dim i As Long
i = 40
' DOESNT LIKE THIS LINE HERE
Selection.Start = 0
Selection.End = 0
Selection.MoveDown wdLine, 3, wdMove
Selection.EndOf wdLine, wdExtend
strText1 = Selection.Text
i = i + 1
Selection.Font.Size = i
Selection.End = Selection.Start
Selection.EndOf wdLine, wdExtend
strText2 = Selection.Text
Loop While strText1 = strText2
Selection.Font.Size = i - 30
Selection.End = 0
Dim t As Long
t = Timer
Do While Timer < t + 3
objWdDoc.Saved = True
Set objWdRange = Nothing
Set objWdDoc = Nothing
Set objWdApp = Nothing
Using Word 2002 Commands For Word 2000
I created a program in VB.net which runs great under Windows XP with Word 2002. It creates an instance of word and writes text then saves the file in a specified folder.
I referenced the Microsoft Scripting Runtime object library in order to save the file.
I also referenced the Microsoft Word 10.0 Object Library to use Word.
I now have to install my program on a computer running Windows 98 and Word 2000. The program itself runs in Windows 98, but when I try to create an instance of Word the program crashes. Does anyone know what the problem could be and how i could fix it? Do i need to link to different libraries? Is it a problem with Windows 98 or with Word 2000 or both?
I would appreciate any help, thanks.
Run Userform From A New Word Instance, Word 2000
I want to run my userform/template application from a brand new instance of Word, even if Word is already open and documents have been left open at the bottom of the screen.
The reason for this is because by using Application.Quit wdDoNotSaveChanges (which I need to do), when I come to Exit the userform, I will lose the documents open at the bottom of the screen, which may or may not have been saved previously.
How do I go about this, and where will I need to put the code - ie if code for a new instance is put at the top of the userform, then the userform would most probably have already been generated before it reads code for the new Word instance - if you get my drift?
Do I need to add something to a macro?
As I'm new to VBA, please could any replies be fairly plain and simple.
Opening MS Word 2000 And MS Word 97 In VB***RESOLVED***
Hello out there
My problem is that I have code that can open MS word document in VB, but it only opens word document very well in MS Word 2000. It gives an error when opening in MS word 97. Error number -2147417851 (80010105) Automation error. The code looks like this:-
Private SubDim wrd As New Word.Applicationwrd.Visible=Truewrd.Documents.Open "C:Filename" Set wrd=Nothing End Sub
This code only opens MS word 2000 document but gives an error in MS word 97. Run time error -2147417851 (80010105) Automation error.
I do not understant why it does this, it supposed to open all MS documents without a problem.
Thanks in advance.
MS Word 98 Object Library With Word 2000
I wrote a program that uses the Microsoft Word 8.0 Object Library to write to Word documents, etc. Will that program run unmodified on a PC that has Word 2000 rather than Word 97?
Word 2000: Format Word Within A Bookmark
Can anyone tell me if this can be done. With VBA code, I want to add some text to a bookmark within my document but as I am adding the text to the bookmark, I'd like to turn on/off Bold, add Underline, add comments, etc...
I am able to do this outside of a bookmark with the Selection method, but wanted to know if I can do this with a bookmark.
My sample code to format the text of a selection is below, which I would like to be able to do the same thing for a bookmark (Notice how I can turn on/off Bold just before/after I insert my text, and turn on Comments):
.TypeText Text:="This is my first paragraph"
.TypeText Text:="This is my 2nd paragraph. Now I will "
.Font.Bold = True
.TypeText "BOLD some words. "
.Font.Bold = False
.TypeText Text:="Bold is now turned OFF. Now, add a comment
.Comments.Add Selection.Range, "This is my comment"
.TypeText Text:="This is my 3rd paragraph."
Is this possible to do with a bookmark? My code to select the bookmark is: ActiveDocument.Bookmarks("myBookmark").Select
If I try the same thing using my bookmark, as I did in my above example, the text gets put after the bookmark, not within the bookmark. And, if I rerun my code over and over, I get repeating paragraphs, because the bookmark does not get cleared out, since my sample text is actually in the document, not within the bookmark.
Word 2000: Delete A Word Page With VBA
I have a Word 2000 Template that has a bunch of bookmarks and a Data Entry Form, that the user creates a New Document off of. When the user creates a new document based on this template, there is a Macro that the user can run that loads a user entry Form allowing the user has to enter data. When the user clicks the OK button on the form the following 2 things happen:
1. All the bookmarks within the document get updated based on data from the User Entry Form
2. At the end of the document, a particular Word document (Test.doc) is inserted at the "Attachment" bookmark
Everything works fine the first time the user clicks the OK button. However, if the user reruns the same macro within the same document, re-enters different data on the user entry form and clicks the OK button, all the bookmarks update properly, but the inserted file gets added after the 1st one (the 1st one does not get cleared out) - so the user has 2 inserted files. For instance, the first time the user runs the letter there is 3 pages (2 pages + 1 File), and if the user runs it again, there will be 4 pages (2 pages + 2 Files - 1st one and now the 2nd one), and so on... Basically, each time the user clicks the OK button, the appropriate file keeps getting appended to the end.
My problem is, how can I remove the file (Test.doc) that was inserted on the 1st run before we insert the file on the 2nd run? Is there a way to delete the entire page before we insert the file, that way all the data is cleared leaving me with only 2 pages, before I do my insert? My sample code of inserting the file is below:
Dim bmRange As Range
' This is my bookmark where I want to add the file
Set bmRange = ActiveDocument.Bookmarks("Attachment").Range
' Insert a Page Break after the bookmark so that file being inserted is on it's own page
' Insert the Test Document
.InsertFile FileName:="C:Test.doc", Range:="", _
' ConfirmConversions:=False, Link:=False, Attachment:=False
VBA Word Template Word 2000
I have written a Letter template an once launched a user form pops up giving you the option to type in your details. Now this all works okay but when you save the template and then re-open the template The userform does not appear allowing you to make chnages to the template. Is there any code or a way in VBA you can get the userform to launch and to load all the informtion first typed into the userform?
Here is my code in the 'My Document' part.
On Error Resume Next
Dim oform As frmletter
Set oform = frmletter
oform.txt10.Text = Format$(Date, "d mmmm yyyy")
If oform.Tag = "OK" Then
' updating bookmark called "TO"
Dim bmrangeTo As Range
Set bmrangeTo = ActiveDocument.Bookmarks("To").Range
bmrangeTo.Text = oform.txt1
Set bmrangeTo = Nothing
' updating bookmark called "TO1"
Dim bmrangeTo1 As Range
Set bmrangeTo1 = ActiveDocument.Bookmarks("To1").Range
bmrangeTo1.Text = oform.txt1
Set bmrangeTo1 = Nothing
' updating bookmark called "ADDRESS"
Dim bmrangeAddress As Range
Set bmrangeAddress = ActiveDocument.Bookmarks("Address").Range
bmrangeAddress.Text = oform.txt2
Set bmrangeAddress = Nothing
' updating bookmark called "YourRef"
Dim bmRangeRef1 As Range
Set bmRangeRef1 = ActiveDocument.Bookmarks("YourRef").Range
bmRangeRef1.Text = oform.txt8
Set bmRangeRef1 = Nothing
' updating bookmark called "OurRef"
Dim bmRangeRef2 As Range
Set bmRangeRef2 = ActiveDocument.Bookmarks("OurRef").Range
bmRangeRef2.Text = oform.txt9
Set bmRangeRef2 = Nothing
' updating bookmark called "DATE"
Dim bmRangeDate As Range
Set bmRangeDate = ActiveDocument.Bookmarks("Date").Range
bmRangeDate.Text = oform.txt10
Set bmRangeDate = Nothing
Set oform = Nothing
Set oform = Nothing
Thank you in advance.
Difference Of VBA In Word 2000 And Word XP [Please Help]
I have a .net application in C# that intracts with microsoft word. Previously it was designed for win xp and office xp. Now I would like this to work on Win 2000 and office 2000. But it is giving some problem.
I looked into the code and could figure it out that some functions are giving exceptions. Following are examples.
1. Document.SaveAs method works in Word XP but not in Word 2000. However Document.SaveAs2000 works in Word 2000.
2. Range.PasteAndFormat works for Word XP but not for Word 2000. However Range.Paste() works in Word 2000.
Is there any reason behind this. Is it somewhare mentioned in Microsoft website?? Could you please get me some link where this information is mentioned.
Are there some other functions that behaves similar to above mentioned?
Thanks in advance.
edit: moved from .NET Newbies forum as it's not about .NET specifically
Edited by - Machaira on 4/26/2006 5:45:48 AM
Word Macro Insert File/ Append Table Macro Issue.
I was wondering if someone could help me with this problem...
When I use the following code to insert a table (from an external file), the table that is inserted does not append to the table in first document (which is what I want it to do)...
Selection.InsertFile FileName:="m:cat.DOC", Link:=True
Would anyone know how I can make the contents of this file append to the table in the first document?
Thanks so much in advance,
Word Macro Editor Opens When I Misspell A Macro Name
I'm using Word 2000, and pressing Alt+F8 to access macros - just text strings - and here's the trouble:
I'm trying to make it possible for everyone here to use Word macros from the server. I've put a file out there called Macros.dot and it works great. Every machine in the building can see it and use it. Trouble is, if a user misspells a macro name the macro editor opens by default. It doesn't realize the user has misspelled something and thinks the user wants to write a new macro under the "new" name. User can click the X to close the editor, of course, but has now created a blank macro with a name very similar to a real macro. This will drive people (especially the less tech savvy) nuts, and clog up the file Macros.dot with garbage.
Is there a way to disable the macro editor from opening if an incorrect (nonexistent) macro name is typed? A check box somewhere, perhaps? I've tried but can't seem to find it, if it's there.
Openning Excel And Running Macro From Word - Macro
Ok - I have a DB which I export to Excel, I then run a macro to "Groom The Data". I then run word and run a Macro (MailMerge to print labels) which retrieves data from the excel spreadsheet groomed above. Everything is working fine, despite my novice knowledge of VB, but I would like to do this in a single click.
I use a command line shortcut to Launch word and automatically have it run the macro, but I still have to Launch Excel and manually run its macro first.
I did not find a command line switch to make excel launch and run a macro. Is there any way I can Lauch Word have its Macro link to excel, then launch and run the excel macros before performing the macro I have set up in word (mailmerge)
In Other Words I have working macros in Word and Excel, I want the Word Macro to force the Excel macro to run before completing the rest of its duties.
Mail Merge Access 2000 With Word 2000/XP And Pass Variables
Hi, I debated posting in newbies, because I'm kind of learning VBA on the fly, and am not very good at all.
I am trying to Mail Merge an Access 2000 database with Word 2000 & Word XP.
I modified the code I got from the Microsoft Solution Base to try to introduce variables to allow me to merge more than one table and SQL query with more than one Word document.
This code works without the variables, when I just type everything directly. Unfortunately, I need the ability to merge multiple documents/tables.
Sorry if its sloppy code, I haven't really got much of an idea of what I'm doing in VBA yet.
Can anyone help me debug this, and maybe give me the syntax to use in my Macro for MergeIt(var,var,var)
I also need a way to email similar form letters. This is for a membership expired notice - some get mailed/faxed, so need to be printed, while some should be emailed. I've read that sendobject doesn't do so well. - is there a way to merge into Word (or Outlook) and automatically email these notices?
Thanks very much!!
Function MergeIt(docaddy, sqltable, sqlstr)
DoCmd.OpenQuery "Dues Expired Calculate"
DoCmd.OpenQuery "Dues NOT Expired Calculate"
DoCmd.OpenQuery "Dues Are Expired"
Dim objWord As Word.Document
Set objWord = GetObject(docaddy, "Word.Documents")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source.
Name:="F:workooo dbOOO Main Database.mdb", _
' Execute the mail merge.
objWord.MailMerge.Destination = wdSendToNewDocument
'The following line must follow the Execute statement because the
'PrintBackground property is available only when a document window is
'active. Without this line of code, the function will end before Word
'can print the merged document.
objWord.Application.Options.PrintBackground = False
Thanks for any help!
Edited by - case on 7/31/2003 7:40:22 AM
Word 200 Vba Macro Help - Enable Track Changes In A Macro. Thanks
I was able to find a macro which takes an already mail merged document, and saves each each document as a separate file. The document's filename is taken from the already merged document. The script works. It's in red. See below.
The problem is I need to enable the track changes option.I recorded the following macro. It's in blue.
.TrackRevisions = True
.PrintRevisions = True
.ShowRevisions = True
I tried to incorporate this code(blue) into the code (red) below. I added it between ActiveDocument.Sections.First.Range.Cut and Documents.Add but it didn't work.
ActiveDocument.TrackRevisions = True
ActiveDocument.PrintRevisions = True
ActiveDocument.ShowRevisions = True
It turned on track changes but it didn't create each new document. What am I doing wrong?
Desperately Seeking help!!
Script works perfectly.
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by a
' mailmerge as a separate file.
Letters = Selection.Information(wdActiveEndSectionNumber)
Counter = 1
While Counter < Letters
Application.ScreenUpdating = False
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "C:MERGELETTERS"
Docname = sPath & sName
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
ActiveDocument.SaveAs FileName:=Docname, _
Counter = Counter + 1
Application.ScreenUpdating = True
Word XP Vs. Word 2000
I have an application that writes information off a sql server db to a word document into tables. When viewing these docs in word xp the tables borders dont show but when using word 2000 it does show. Why would this be? Any suggestions?
MS Word Macro Help
All I need is the VB code at the bottom rewritten so that it will strip the red paragraph out of the following example document and place it in a text file (e:illing.txt):
Here is the example document:
Febuary 8, 2005
12 Evergreen Rd.
RE: Document example
%%%Febuary 8, 2005,”345ABB7”,” TDLR”,Opposition,”preparing correspondence to Jane Doe regarding trademark renewal deadline approaching on March 17, 2005, seeking instructions regarding same”,”46547”,””,””
We note that there is approximately one month remaining within which to effect a timely renewal of the above captioned trademark registration. Should we not file the necessary renewal documents in advance of the March 17, 2005 deadline,
Yours very truly,
FURMAN & KALLIO
On Error GoTo errorhandler
'set up variables
Dim SectionNumber As Integer
Dim RangeToSpike As Range
Dim AccumulatedText As String
'loop through sections
For SectionNumber = 1 To ActiveDocument.Sections.Count
'mark the first paragraph of the section, less the paragraph mark
Set RangeToSpike = _
RangeToSpike.MoveEnd wdCharacter, -1
If RangeToSpike.Start = RangeToSpike.End Then GoTo GetNextSection
If Mid(RangeToSpike.Text, 1, 3) <> "%%%" Then GoTo GetNextSection
'add the first paragraph to the spike, then delete it
RangeToSpike.MoveStart wdCharacter, 3
AccumulatedText = AccumulatedText & RangeToSpike.Text & vbCr
'create a new document and dump the spike into it
Documents.Open FileName:="e:illing.txt", ConfirmConversions:=False, Format:=wdOpenFormatText
If Selection.Paragraphs.First.Range.Characters.Count > 1 Then
Thanks, your help is much appreciated!
J'ai un document word d'un nombre certain de pages avec sur chaque début de page un commentaire contenant soit VC soit VS.
J'aimerais créer 2 boutons dans ma barre d'outils:
·Un qui permette de selectionner et copier les pages qui contiennent le commentaire VO dans un nouveau document nommé Version S
·et un autre bouton qui permette de selectionner et copier les pages qui contiennent le commentaire Vs dans un nouveau document nommé Version C.
Pourrais-je avoir le code VBA de cet algorythme s'il vous plait:
Parcourir Doc tant que fin doc != vrai
Si commentaire Page = VS
Alors Selection Page
Ouvre New Doc = "Version S"
Coller Selection dans "Version S"
Imprimer "Version S"
Merci beaucoup d'avance
Hello everyone, Does anyone have any ideas on how to do a find and replace in a form field on a protected word Document? Everything that I have tried has given me an error. Pretty much the error is saying that command is not available. any ideas are welcomed. thanks
Macro For Word
Just wondering if somebody know how to create a macro in word that will set the "Print To File" property in the print box to be false/unchecked. Because I have this macro on my machine, but every time I try to run this macro, the checkbox for the "Print To File" it's always getting checked up. Anyway here's my code:
Dim name As String
oldprint = ActivePrinter
ActivePrinter = "Acrobat Distiller"
name = WordBasic.GetDocumentVar$("NAME")
ActiveDocument.PrintOut Background:=False, OutputFileName:="c: empin" & name & ".pdf", PrintToFile:=False:
ActivePrinter = oldprint
Any suggestions are greatly appreciated.
I need some assistance for a word macro that does this:
When I want to save the document (Alt-S), I want my save as directory to default to a particular path. ("C:Docs"), but I do not want to use Tools>Options to set the directory. Naturally, don' t want nor need the default word save prompt to appear.
Thanks for help.
Macro In MS Word?
I wanted to ask if it is possible to make a macro similar to that in excel which will highlight same numerical values across the document automatically. It would be a gift from above to be able to make it highlight values in predefined ranges in different colours on its own - like highlight values between 120 and 140 in red and values between 390 and 467 in green.
Thank you very much !!!
Any thoughts are appreciated!
Run A Macro In Word
I have to run 2 macros in winword with invisible mode.Currently I am using the following code.Some body help to run two macro automatically one by one.That is run the first one and run the second one.
Dim myword As Object Set myword = CreateObject("Word.Application") myword.Documents.Open (G_Working_Folder & "" & G_File_Name & ".doc")' myword.AddIns.Add "C:ToolEditing.dot", Install:=True' myword.AddIns.Add "C:ToolConversion.dot", Install:=True' myword.AddIns.Add "C:ToolConversion.dot", Install:=True myword.AddIns.Add G_Tool_Folder & "Editing.dot", Install:=True myword.AddIns.Add G_Tool_Folder & "Conversion.dot", Install:=False myword.AddIns.Add G_Tool_Folder & "Conversion.dot", Install:=False'
Thanks in advance.
I have a word macro that gets user info from a form and puts it in the document which works fine. The problem is when I open a new document (doc2) and (doc1) is still open. As soon as I open the userform the focus switches back to (doc1). Any ideas.
MS Word VB Macro
I am building a Macro for Word, so I need to know how to go to a specific line postion and write text. There are soooo many objects/properties/functions I get lost everytime I try.
Help With Word Macro's
I need help make a control box w/ a assigned Macro to it send the document to a specified address. The control box is in Word .
Also if possible I do not want the user to know it is being emailed back to us.
I can make the code work in Excel
but can't make it work in Word !! Any help would be appreciated
MS Word- Macro
I have a macro created in MS Word. I want to use it in VB . Is it possible to do ............
Is it possible to programmatically write a macro in the document_Close Event of an existing word document ?
just a little example would help
Word Macro (again...)
I would like to know if there is a way/method to know if a Word document containe any Macro ??? Can i Disabled the macro within that document???