[RESOLVED] Word SaveAs And Display On Screen
I have a word document that I created that will be used as a template in one of the apps I'm working one. The user fills out stuff on a VB screen, and the, in turn, get dumped to Bookmarked locations on my template. All of the works. What I can't seem to get working is the SaveAs and having it display on screen prior to being printed. Here is what I have:
VB Code:
Private Sub cmdPrint_Click()
Dim ObjWord As Word.Application
Dim strFileName As String
Set ObjWord = CreateObject("Word.Application")
strFileName = Format(Now, "mmddyyyy HHMMSS")
With ObjWord
.Documents.Open (App.Path & "\TelephoneLog.doc")
.ActiveDocument.Bookmarks("prov_info").Select
.Selection.Text = (cboProvider.List(cboProvider.ListIndex))
.ActiveDocument.Bookmarks("fye").Select
.Selection.Text = (cboFYE.List(cboFYE.ListIndex))
.ActiveDocument.Bookmarks("type").Select
If optMeeting.Value = True Then
.Selection.Text = ("Meeting")
Else
.Selection.Text = ("Telephone Conversation")
End If
.ActiveDocument.Bookmarks("type").Select
.Selection.Text = (txtSubject.Text)
.ActiveDocument.Bookmarks("people").Select
.Selection.Text = (txtPersons.Text)
.ActiveDocument.Bookmarks("action").Select
.Selection.Text = (rtbAction.Text)
.ActiveDocument.Bookmarks("From").Select
.Selection.Text = (gstrUserRealName)
If chkShowDoc.Value = vbChecked Then
.Visible = True
Else
.Visible = False
End If
.ActiveDocument.PrintOut Background:=True
.ActiveDocument.SaveAs FileName:=strFileName & ".doc"
.Application.Documents.Close
End With
Set ObjWord = Nothing
End Sub
I need to have the document saved as DateTime.doc (i.e., 08052005 092820.doc), and I need to set it up so that user can either display it on the screen prior to printing, or never see it and send it directly to the printer.
Re: Word SaveAs And Display On Screen
*Sigh* The requirements have just changed.
Now, it MUST be shown on the screen, and then they will use Word itself to print it.
I need to disable the Save menu item, and Save toolbar item, so that the only option available to them is a drop down menu item under File of Save As...
So, my current two questions are:
How do I display this puppy on the screen?
How do I disable the ability to do a Save, leaving only the Save As option available?
Re: Word SaveAs And Display On Screen
Displaying it is easy.... objWord.Visible = True... even after the object falls out of scope, Word will still be around.
Disabling the save button..... hmmm...
The only thing that comes to mind, and this sounds crazy, but, after saving it, close it, then re-open it in read-only mode. The save buttons will still be enabled, but it will force a Save As if they try to do something with it.
It's been a while since I delved into the Word Object, but I also wonder if there's a way using automation to change toolbars.... you could create a new one, with only the print button on it, then remove all of the other toolbars.... ???
Tg
Re: Word SaveAs And Display On Screen
I do have the objWord.Visible thing set to True but the document still doesn't show up. :confused:
And, I need to disable the Save button before they save it. If I don't, then will more than likely overlay my template and get themselves all bollax'ed up. I have to limit their options to just Save As.
Signed:
A complete VBA noodnick
Edit: Hmmmm...I wonder if there is a way to automatically popup the SaveAs dialog box as soon as the document opens...
Re: Word SaveAs And Display On Screen
Ok, we are making progress. I figured out why the .Visible = True wasn't working for me.
Now all I need is the ability to disable Save from the dropdown menu, and disable the save icon from the toolbar.
Re: Word SaveAs And Display On Screen
Check this out....
Save your doc as a word template (.dot) file....then when you do the .Open, point it to the dot file instead..... then any hitting of the save button will popup the usual "Save As" dialog one would get if opening a new doc by template.
I know this works because I jsut built a reporting tool for an app using Word as the "engine" and that's exactly how I did it. saved the document as a template, complete with all my book marks and such. Now when I .Open it pointing tothe dot file, I get Document1 using the template. If my users then hit the save button, they get asked where to save Document1.
It's pretty cool actualy.
Tg
Re: Word SaveAs And Display On Screen
That sounds cool. I'll give it shot.
Thanks.!
Re: Word SaveAs And Display On Screen
Does anyone know how to view Bookmarks that have been created within a Word document?
Re: Word SaveAs And Display On Screen
You could try
VB Code:
Dim i As Integer
With objWord.ActiveDocument.Bookmarks
For i = 1 To .Count
MsgBox .Item(i).Name
Next i
End With
Re: Word SaveAs And Display On Screen
I just want a visual display. Kind of like if you hit that paragraph button on the tool bar, it will display all the paragraph symbols in the document. I was hoping there would be something like that that would show me the location of all of my bookmarks.
Re: Word SaveAs And Display On Screen
Ok then this one instead
VB Code:
objWord.ActiveWindow.View.ShowBookmarks=True
Re: Word SaveAs And Display On Screen
You can intercept Words Save & SaveAs functions simply by creating your own with the same names as Words.
Words Save control looks for the macros - FileSave & FileSaveAs to save documents.
so you can intercept them by writing the following subs.
and
Obviously at this point you would need to use the CommonDialog control to create your own Save method.
Re: Word SaveAs And Display On Screen
This ins't a macro situation.... at least I don't think it is. In fact I'm pretty sure it isn't.
It's a case of using Word as a sort of reporting engine from VB.
Either way, does that really work though?
Tg
Re: Word SaveAs And Display On Screen
Another method would be to just disable the menu items not needed in the document..
e.g.
VB Code:
objWord.ActiveDocument.CommandBars("File").Controls("Save").Enabled = False
Re: Word SaveAs And Display On Screen
Yep the FileSave & FileSaveAs methods work, and would work in the described situation.
You just have to include them in your reporting template and they will stop users being able to save or SaveAs normally but instead your code takes over.
When the user hits the Save button, it will be intercepted by your code, try it if you like.
paste the following into a module in your template & then press the save button and you will see what i mean.
VB Code:
Sub FileSave()
msgbox "Intercepting the Save Command"
End Sub
Re: Word SaveAs And Display On Screen
Hack
Is this resolved then or did you forget about it?
Re: Word SaveAs And Display On Screen
Quote:
Originally Posted by NeedSomeAnswers
paste the following into a module in your template & then press the save button and you will see what i mean.
VB Code:
Sub FileSave()
msgbox "Intercepting the Save Command"
End Sub
Yep. This works. Thanks.
Quote:
Originally Posted by dannymking
Hack
Is this resolved then or did you forget about it?
Yes, and yes :blush:
Thanks for reminding me.
Re: [RESOLVED] Word SaveAs And Display On Screen
I don't give up on something until i know it's resolved.. :D
Sorry to be a pain..