Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Opening Saveas Dialog Box From A Macro??? In Word

I have been working on a macro in word with a userform, now in the userform i have a save button. what is the vba code to make the saveas dialog box some up, so the user can locate the folder where they want to save the document, (same as file > saveas) it is important that i run this from the macro, so that i cant risk someone stuffing the document up.

Also how can i do the same thing for the print button. by getting the print dialog box to open.

Also, can someone tell me how to make error messages pop up, so forexample someone forgets to fill in something it will say that something isnt filled in please fill in this field(s). also for fields that involve numbers, how do i make it so that only numbers are allowed not letters.


Edited by - kristoforl on 10/18/2003 4:25:16 AM

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Opening The SaveAs Dialog In Outlook

The code to open a saveAs dialog is pretty simple in Microsoft Excel, eg:

DialogResult = Application.GetSaveAsFilename(InitialFilename:="C:WorkMyfile.xls")

However, I can't seem to get something similar to work using
Outlook 2000 (the above code doesn't work)

What I would like is to open up a saveAs dialog box, where the save point is at a folder I choose in the code...

I've also tried this:

ActiveExplorer.CommandBars("Email").Controls("Save As...").Execute

(After adding the "Save As" button to a custom toolbar I made)

However, that will only load up the Save as Button with the save folder as mydocuments or something.

Many Thanks

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")
End If

With frmTestCatSrch.msword.Dialogs(wdDialogFileSaveAs)
.Name = "tstcat.doc"

End With

End Sub
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?

Many thanks,

Runtime Error 4198 In Word Macro When ActiveDocument.SaveAs

I keep getting the 4198 runtime error when attempting to run the following code. I've no idea why.
I would be grateful for any help;

thanks in advance


/*********** CODE ***********************/

Private Sub Document_Open()
    Dim prop As String
    Open "C:Speed2001Installation.Properties" For Input As #1
    While Not EOF(1)
        Line Input #1, prop
        If Left(prop, 24) = "INSTALLATION_LOC_REPORTS" Then
            location = Mid(prop, 28)
        End If
    Close #1

    'select the entire document so that bookmarks can be found and table of contents generated later
    Selection.HomeKey Unit:=wdStory
    'Move to the top of the doc before saving..
    Selection.HomeKey Unit:=wdStory
    saveAsLocation = location + "data
eports" & "mnds"
    'Save the document to the users default word folder..
    ActiveDocument.SaveAs fileName:=saveAsLocation, _
    FileFormat:=wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:=True, _
    WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
    SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
End Sub

/************** END OF CODE *******************/

How Do I Stop The Print Macro Definition Dialog From Opening
Hi There,

I've got a simple autoexec macro that has three steps (using MS Access 97):

Opens a reports
prints out the report
Quits MS Access

However when it is run a dialog box pops up: "Print Macro Definition" with three check box options.

I do not want this to pop up. How do I turn it off?????

Regards, Troys.

Edited by - troys on 3/9/2004 7:39:00 PM

Opening Word Doc From Excel Macro
Is it possible to run a macro in Excel that will open a Word document in Word?

Prevent Word Document Opening Without Macro Support?

Been trying to find a way to prevent a word document from opening if the user selects "disable macros".

Anyone know if this is possible, and how?

Been driving me nuts........

SaveAs With SaveAs Dialog?
Hi all :)

I found this on MSDN, and is *almost* what I need - the difference being that I'd like to bring up the Save As dialog, so that the user can choose the filename and location to save the sheet.

Sub SaveSingleSheet()

Worksheets("Sheet1").SaveAs filename:="test.xls", _

End Sub

To be honest, I have no idea what to try - I've tried just: Worksheets("Sheet1").SaveAs, but to no avail. I haven't found this in a search of this forum, and as I said, that's all I could find on MSDN.

A poke and prod in the right direction would be much appreciated, thanyou ;)

Macro File Saveas
Anyone know why this macro won't work?

Sub SaveDocHTML()

ActiveDocument.SaveAs , Application.FileConverters("HTML Document").SaveFormat
MsgBox "Saved in HTML format successful."

End Sub

- OR -

Sub SaveDocHTML()

ActiveDocument.SaveAs , Application.FileConverters(6).SaveFormat
MsgBox "Saved in HTML format successful."

End Sub

the broken line is really on one line in the code window.

Thanks for your assistance yet again.


Excel SaveAs Macro
I am trying to figure out a way to have my Excel macro save the workbook/worksheet to a tab delimited file,
but not change the current worksheet file name.

Basically I want to save the tab delimited file, but still have the workbook/worksheet retain its original file name.

I have the macro built that works fine, only I have to close the workbook without saving and re-open it again.


ChDir "K:Data"
Application.DisplayAlerts = False
Worksheets("Sorted").SaveAs Filename:= _
"K:DataMyFile.txt", _
FileFormat:=xlText, ReadOnlyRecommended:=False, CreateBackup:=False
Application.DisplayAlerts = True
ChDir "K:Databases and Logo Lists for Site"
ThisWorkbook.Close savechanges:=False

This is a pretty simple macro, but I want to save the file without making the current workbook have a name change.

Any suggestions?

SaveAs Dialog Box
The following code works fine to open the common Dialog box and show Images, but what is the code For the (Save As) Dialog Box to save the image opened to another file.

Public Sub AllPictures() 'This opens a file via Common dialog box
On Error GoTo Cancel 'Set(Cancel Error) to true in properties window
CommonDialog1.DialogTitle = "CHOOSE A FILE TO OPEN" 'Title for Dialog Box
CommonDialog1.InitDir = Route
CommonDialog1.Filter = "IMAGE FILES(*.jpg, *.bmp)|*.jpg;*.bmp|ALL FILES (*.*)|*.*"
CommonDialog1.ShowOpen 'Show Dialog box for open
Image1.Picture = LoadPicture(CommonDialog1.FileName)
Route = CommonDialog1.FileName 'This brings common dialog back to originally selected page unless changed
End Sub

Thanks RSH

SaveAs Dialog In Outlook?
i need to open a SaveAs dialog in outlook, but can not find a function?
from this SaveAs dialog, i also need to specify a initial start location,

Can anyone please help.


SaveAs Dialog Box Question
I'm using the following in a macro:


How do set up the "save in" selection box to default to a cetain fiel loacation? Also, I want the file extension to default to an .xls and the file name to default to "Change me." Any thoughts?

Thanks for the help in advance!

Excel VBA And SaveAs Dialog Box

I want to save some spreadsheets as part of a macro but I want to let the user choose where to store them - in other words I want to use the SaveAs dialog box.

I know how to do this in VB but I can't get it to work in Excel/VBA.

Does anyone have any ideas??



Cancel On Saveas Dialog


saveFile = oWord.ActiveDocument.Name
myString = Split(saveFile, ".")
saveFile = myString(0)
CommonDialog1.FileName = saveFile & "_"
saveFile = CommonDialog1.FileName


oWord.ActiveDocument.SaveAs FileName:=saveFile, FileFormat:=wdFormatTemplate, LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
End If

Excel VBA SaveAs Dialog Issue


There is also the 'GetSaveAsFilename' method; look it up in your Excel VB help.

I've implanted this code into VB for getting Save as. The problem i keep getting is that it showed only the window and does NOT save the actual file like i want to get from the save as.

PHP Code:

fileSaveName = Application.GetSaveAsFilename( _
    "\FilelocationNamefile.xls", fileFilter:="Excel Files (*.xls), *.xls")

If fileSaveName <> False Then
    MsgBox "Save as " & fileSaveName 

If anyone can tell me what i do wrong here pls tell me ive been working on this for more then 3 hours!

The problem with the code above is that i have VB-office only so not all the commands will work in my stationary.

Thanks, Axle

Edit by Moderator:
Please post your own threads to ask your own questions, posting links to other threads as required.

Thank you.

Excel VBA SaveAs Dialog Issue
I am trying to use VBA to bring up a SaveAs dialog box with the file name pre-filled in.
I can get the box to show up with the file name, but I can never save the file. I get an error. I tried a few other things that make the error go away but then it just doesn't save it at all.

here is the code.

1 Dim SaveAs1 As FileDialog
2 Dim vrtSelectedItem As Variant
3 Dim SaveFile As String
4 SaveFile = Worksheets("units").Range("myFileName")
5 Set SaveAs1 = Application.FileDialog(msoFileDialogSaveAs)
6 With SaveAs1
7 .InitialFileName = SaveFile
8 End With
10 SaveAs1.AllowMultiSelect = False
11 'SaveAs1.Show
13 If SaveAs1.Show = -1 Then
14 vrtSelectedItem = SaveAs1.SelectedItems(1)
15 ActiveDocument.SaveAsEx vrtSelectedItem, visSaveAsWS
16 End If
I am getting the error at line 15

I am not sure what to do at this point, I've looked every where and most places just describe how to do this automatically but I want the user to choose a folder.

Edit by Moderator:
Please post Exel questions, in the Excel forum.

Please use the [vb][/vb] tags when you post your code. Edit or reply to this post to see how.

Thank you.

Question About Open/SaveAs Dialog
Is there a way to either disable the "Up One Level" option on the Open/SaveAs dialog or somehow prevent the user from changing the directory?

Will appreciate any suggestions.

How To Fill In SaveAs Dialog Box And Press OK?
I am using the axwebbrowser. I have automated the navigation of a website.

The program presses one of the buttons on the website and "Open/Save/Cancel" Dialog appears.

How can I programatically press the Save and then fill in the name and click the save button

Howto Show A Saveas Dialog In Outlook

Can anyone tell me Howto show a saveas dialog in outlook.

Greetings Raymond

Powerpoint SaveAs Dialog In Office Com Addin
I am developing Com based Add-in for Office Application using IDTExtensibility2.
I notice in Excel and Word they have SaveAs Dialog. however,
for Powerpoint i can't find to open saveas dialog.
for excel word here is the source.
Dim wordDoc as new word.applicationi
With wordDoc.Dialogs(wdDialogFileSaveAs)
.format = formatToUse
wordDoc.ActiveDocument.SaveAs .name, wdFormatDocument
End With

Any one has any idea about how to launch the saveas dialog in powerpoint

Prevent Outlook Security Dialog - SaveAs
I am receiving an Outllok virus warning dialog when performing a SaveAs.
Whilst there has been a number of posts on similar issues, I thought that
a SaveAs wouldn't alert Outlook this way.

Below is an attached capture of the dialog.

I have coded this in VBA and now in VB with the same result.

I have cut the code down to the relavent part below:

Option Explicit

Const MSG As Integer = 3 (similar to olMSG in VBA)

Private Sub Form_Load()Dim objOutlook As Object
DimobjExplorer As Object
Dim objSel As Object
Dim intIdx As Integer
Dim strSubject As String

'On Error GoTo Err_Handler

Set objOutlook = GetObject(, "Outlook.Application")
Set objExplorer = objOutlook.ActiveExplorer
Set objSel = objExplorer.Selection

For intIdx = 1 To objSel.CountstrSubject = Replace(Replace(objSel.Item(intIdx).subject, ":", " "), "/", "-")
objSel.Item(intIdx).SaveAs strSubject, MSG

Set objOutlook = Nothing
Set objExplorer = Nothing
Set objSel = Nothing

End Sub


Common Dialog Control SaveAs Question
Hello I am using VB6 and am trying to use the Common Dialog control to allow my user to name a file that the program is creating.  The trouble is I cannot figure out how to generate an alert to the user if they have selected a filename that is already taken and are thus about to overwrite an existing file.  Can anybody help me??  

Here is some of my code:
cdlCommon.CancelError = False
cdlCommon.InitDir = App.Path & "pictures"
cdlCommon.FileName = Format(Now, "mm-dd-yyyy")
cdlCommon.Flags = cdlOFNHideReadOnly
cdlCommon.Filter = "Picture Files (*.jpg)|*.jpg|"  

 cdlCommon.FilterIndex = 1

Dim newpic As String
newpic = cdlCommon.FileName

    Dim fs, A As Object
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set A = fs.createtextfile(newpic, True)

Again, the code is fully functional I just need to know how to generate an alert for the user if an existing file name is about to be overwritten.

Thank you very much.

Adding Save Locations To SaveAs Dialog
I am trying to achieve the following and I would be really helpful if
someone could tell me
firstly if it is possible and secondly some pointer on how to go about it.

I want to add entries in the Windows drive list box that appears in the save
as dialog box
in Windows applications.

The entry should just appear as either an extra drive or a even better a
parent like the
my computer, neighborhood Network, or Internet Locations (ftp) which I can
add serveral
children to (like the drives under my computer).

I have no real idea where to start and I would be greatful of any help
anyone can give even
if it is pointing me in the right direction

Thanks is advance for any help you can give.

*** Resolved ***Save Highlighted RTF Text Using COmmon Dialog SaveAs
A while back someone raised the question as to how to save the highlighted text to a file and several wrote and gave examples as to how this can be accomplished. However, as I remember (I can't seem to find the original post), they all used a coded file name and path.

Can anyone show me how to save the highlighted text from a RTF box to a file through the Common Dialog SaveAs so that I can give the highlighted text a filename and path?

It would be most appraciated.

Rev. Michael L. Burns

How To Tell Word The SaveAs Name From VB
Hello All,

Another interesting question I hope someone can answer. Right now I create a word document from a template and pump in0 specific information from VB. The problem for me lies in the SaveAs - I want to display a certain name in the Word SaveAs dialog box and not the usual first line of text in the document. I tried changing the Document.Name and Document.Fullname and even the Document.BuiltInDocumentProperties(wdPropertyTitle) properties. It still defaults to the first line of text in the document which is not what I want the user to have. I don't want to have to actually use the Document.SaveAs feature, then make the user change the name and kill it if he wants something else.

Any suggestions?


Word VB - How To SAVEas
Alirght this site is fantastic and thank you for all the help so far. I got the "SaveAs" language at the bottom from another posting but its not working. I want to save a file name using standardized naming coventions by pulling the name and date off the form and SaveAs. I get "Syntax Error" on the saveas line. I'm using VB through Word.

Private Sub cmdCovForm_Click()
Dim cMonth As String
Dim cDay As String
Dim cYear As String
Dim cName As String

cMonth = cmbMonth.List(cmbMonth.ListIndex)
cDay = cmbDay.List(cmbDay.ListIndex)
cYear = cmbYear.List(cmbYear.ListIndex)
cName = txtFacilityName.Text

strApp = "Word.Application"
Set objapp = CreateObject(strApp)
objapp.Visible = True
objapp.Documents.Open "S:Admin Support - IS Credit ServicesData Sheet Templates - All DepartmentsMutual Fund LendingCompliance Sheet template.doc", ReadOnlyRecommended = True

objapp.activedocuments.SaveAs ("s:S:Admin Support - IS Credit ServicesCovenant Compliance Forms(cname)& " " & (cDay) & "-" & (cMonth) & "-" & (cYear)")

WORD DOC SaveAs Without Popups ?

Is there any property in the SaveAs method of word.doc that disable any popups ?

The SaveAs done automatically by my application and any pop will stuck it.

Is there any way to block any message ?


Excel To Word - SaveAs....

I have a button in excel that opens a word document.

When the word doc is opened i would like to open the SaveAs dialogue box and save the document as the value thats in A:1.

Eg. SaveAs.Filename = <value in A:1>.doc

Any ideas please

Thanks in advance

Word COM Object SaveAs
I am accessing WORD through a visual basic script. I am simply trying to open a word document and save it as a txt file. When looking at the saveas it shows:

ActiveDocument.SaveAs FileName:="file.txt", FileFormat:=wdFormatText

When using an external VB script this syntax does not compile and is incorrect. I simply tried:

ActiveDocument.SaveAs "file.txt"

This someone works. The word document contains formatting that does not convert to a text file. So when you manually go to save the file through the gui you get a prompt that says:

Fle may contain features that are not compatible with Text Only Format. Do you want to save the document in this format? If you click yes it creates a text document. If you click no it saves a text document in a word format. Given this I tried rewriting the saveAs like:

Activedocument.SaveAs "FileName:=file.txt, FileFormat:=wdFormatText"

This was to try it as a whole string which still did not work. So how do you save a text format and make it bypass the prompt?


WORD DOC SaveAs Without Popups ?

Is there any property in the SaveAs method of word.doc that disable any popups ?

The SaveAs done automatically by my application and any pop will stuck it.

Is there any way to block any message ?


Using A Bookmark As A SaveAs File Name Word VBA
In an Excel worksheet it is possible to use the text in a cell for the SaveAs file name. For example:

ThisWorkbook.SaveAs FileName:=Worksheets("Sheet1").Range("A1").Value
Dim myFile As String
myFile = Range("A1")
ActiveWorkbook.SaveAs _
("C:Data" & myFile & ".xls")
End Sub

Is it possible in a Word document to use a bookmarked word as a SaveAs file name. If not, is there any other way to reference a word to use as the SaveAs file name?

Your help is much appreciated.

SaveAs In Word With Mail Merge

I am attempting to create a Macro in Word (2002) that saves files from a Mail Merge batch individually and with unique file names. However the twist is that the unique file name is from a Mail Merge field. At this point, I am unsure of how to; 1) tell the script to grab the information from the main Mail Merge document, when it is currently in the Merged document, and 2) How to get that information into the SaveAs, as a new document name.

Any help would be greatly appreciated!


Capture SaveAs Event On Word
How would i capture the event saveas on word2000?

Trapping SaveAs Event On Word
How can I trap SaveAs Event on Word2000 using its VBA.

Word, SaveAs A List Of Files?
I could sure use a sample of how to loop and open all the files in one folder, and save them back into another folder one by one, but prompted for a new file name with each save.

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)...

Sub Macro1()

Selection.Collapse Direction:=wdCollapseEnd
Selection.InsertFile FileName:="m:cat.DOC", Link:=True

End Sub

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 Doc - SaveAs Doesn't Destroy The Original Temp File
Here's what I'm trying to do:
From a datagrid, I have any number of rows (assume more than one)I select a row, then click a button that opens up a Word document that is a report template, and the template is modified according to values I extract from a database. The report comes out as I expectI change the name of the report using a SaveAs with a dynamic string as the file nameI select a different row, then click the button again to generate another report in Word, but then I run into a problem...
The original template still has a temp file open, so on the 2nd attempt to create a report, I get a message that says that the template is already open for edit, and I get the option to either "Notify" or open it as "Read Only."

The end-user I'm writing the app for always has tons of reports to do, so I need to find out how to clean up the original temp file via VB code.

This is a snippet of what I have at this point:

If irsSites.RecordCount > 0 Then

Screen.MousePointer = vbHourglass

Dim appWord As Word.Application
Set appWord = New Word.Application
Dim WordDoc As Object
Set WordDoc = appWord.Documents.Add("c:Documents and SettingsOwnerMy DocumentsAlltel report blank.doc")

appWord.Visible = True 'False

'Populate appropriate bookmarks in the Word document from the database
'code code code....

'Remove invalid file name characters from site id/site name
Dim lsInvalidFileName As String
Dim lsValidFileName As String
Dim X As Integer
lsInvalidFileName = Trim(txtSiteID.Text) & Trim(txtSiteNm.Text)
For X = 1 To Len(lsInvalidFileName)
If Mid(lsInvalidFileName, X, 1) <> "" And _
Mid(lsInvalidFileName, X, 1) <> "/" And _
Mid(lsInvalidFileName, X, 1) <> ":" And _
Mid(lsInvalidFileName, X, 1) <> "*" And _
Mid(lsInvalidFileName, X, 1) <> "?" And _
Mid(lsInvalidFileName, X, 1) <> Chr(1) And _
Mid(lsInvalidFileName, X, 1) <> "<" And _
Mid(lsInvalidFileName, X, 1) <> ">" And _
Mid(lsInvalidFileName, X, 1) <> "|" _
lsValidFileName = lsValidFileName & Mid(lsInvalidFileName, X, 1)
lsValidFileName = lsValidFileName & "_"
End If
Next X

''''''This is the SaveAs where I would expect that the original temp file would be destroyed, but it isn't. How do I clean it up?

WordDoc.SaveAs ("c:Documents and SettingsOwnerMy DocumentsReports" & lsValidFileName & ".doc")

appWord.Visible = True

Screen.MousePointer = vbDefault

End If
Any ideas?

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 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 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.


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.
With ActiveDocument
.TrackRevisions = True
.PrintRevisions = True
.ShowRevisions = True
End With
End Sub

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.
Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by a
' mailmerge as a separate file.
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter < Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
Docname = sPath & sName

With Selection
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
Counter = Counter + 1
Application.ScreenUpdating = True
End Sub

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:
 Sub AutoOpen()
    MyWord.Visible = False
    MyWord.ActiveDocument.Close False
End Sub
Sub AutoOpen()
  With ActiveDocument
     .PrintOut Background:=False
     .Close savechanges:=False
  End With
End Sub
Sub AutoOpen()
    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
End Sub

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?


Reading The Word Document From Visual Basic Without Opening The Word Applicaiton

I need to access the word document from visual basic without opening the word application. I can do this by opening the word application. Is there any other way to read a document from vb.

I need to search for a particular word in the document without opening the word application.

Waiting for your reply,



Word Automation: Word Window Is Not Shown While Opening From VB (Win2000Server-Office2000)
Hi All,

I am getting problem in word automation with Visual Basic 6.0 and ASP

See, what i have done in my project:
- I have one ASP application
- from this i am calling one VB DLL
- In my VB DLL i am using word automation in which i am opening word for some process.
- all the process what i want to do is done perfectly and my file is also getting stored on particular location
- the process will call that dll first, that dll will call object of word library then it will show word then will do my process, then will save file.

i have win XP and office 2003 installed on my machine. my app is running well on my machine without problem.
I have win 2000 server and office 2000 installed on my production machine. Over here my app is running and functionality is going well enough but the only problem is that i cannot get the word window opened on that machine while my functionality is executing.

Can anyone please help me?


Access To Word: Closing And Opening Word Template
Hi there,
following Function is calling from Access and opens a Word-Template to replace the Bookmark with a Teststring. No Problem, but by a second Call, the Bookmark is not found cause the Worddocument is open in Background (although its closed with "objWord.Quit SaveChanges:=False"). IS there a better Way to close a Worddocument or did anybody find another mistake in that Code? I'm a Newie in VB/Word and I hope this is a clear Description of that Problem.

greetz & Thanks

Public Function test() As Long
    Dim MyRange As Range
    Dim objWord As Word.Application
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = False
    objWord.DisplayAlerts = 0
  Dim oDoc As Word.Document
  Set oDoc = objWord.Documents.Open(getDbPath() & "Templates", ReadOnly:=True, ConfirmConversions:=False, AddToRecentFiles:=False)
  If ActiveDocument.Bookmarks.Exists("TEST") Then
    ActiveDocument.Bookmarks("TEST").Range.Text = "ABCDEFG"
    ActiveDocument.Bookmarks.Add Name:="TEST", Range:=Selection.Range
  End If
savEnv = objWord.Options.PrintBackground
objWord.Options.PrintBackground = False
objWord.Options.PrintBackground = savEnv
objWord.Quit SaveChanges:=False
Set objWord = Nothing
test = 1
End Function

Run A Macro Without Opening Excel
Is there anyway i can run the macros in my Excel without opening the workbook. Any suggestions please.

Opening A File With A Macro

How can I get excel to open a file using a button/macro?

Opening A Workbook With A Macro
 My question is: I used to use a macro that would open up a workbook with a password and put in values and then pull values from that into a new workbook the code to open up that workbook is below. The problem is now that workbook has a marco and a password. I am not sure on how to open up the workbook and have it click enable macro and then do the password.
Any ideas would help very much.

flag = True
    For Each w In Workbooks
        If w.Name = "customsheet.xls" Then
                flag = False
        End If
    Next w
    If flag = True Then
        Workbooks.Open "C:Documents and SettingsUserDesktopcustomsheet.xls", , , , ("go")
    End If


Opening Access Macro
Is there any way that a VB program that is connected to an Access Database can call a macro that is created in Access?

How To Suppress The Macro And Other Dialog In OLE Excel ?

I have successfully embedded an excel sheet in the VB application thanks to Mike and Dr. Loony's help. Now when i run my app it activates the sheet and then gives me the dialog to enable or disable macro. Since i know that everyone will be knowing that this is a trusted enterprise application this dialog does not matter. How can i bypass that dialog without showing it to users ? And there is also one more dialog comes up asking whether i want to save the changes that made to that sheet and i want to bypass that dialog also.

Any help appreciated.


Copyright 2005-08, All rights reserved