Results 1 to 18 of 18

Thread: [RESOLVED] Word SaveAs And Display On Screen

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Resolved [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:
    1. Private Sub cmdPrint_Click()
    2. Dim ObjWord As Word.Application
    3. Dim strFileName As String
    4. Set ObjWord = CreateObject("Word.Application")
    5. strFileName = Format(Now, "mmddyyyy HHMMSS")
    6.  
    7.      With ObjWord
    8.          .Documents.Open (App.Path & "\TelephoneLog.doc")
    9.          .ActiveDocument.Bookmarks("prov_info").Select
    10.          .Selection.Text = (cboProvider.List(cboProvider.ListIndex))        
    11.          .ActiveDocument.Bookmarks("fye").Select
    12.          .Selection.Text = (cboFYE.List(cboFYE.ListIndex))
    13.          .ActiveDocument.Bookmarks("type").Select
    14.             If optMeeting.Value = True Then
    15.                .Selection.Text = ("Meeting")
    16.             Else
    17.                .Selection.Text = ("Telephone Conversation")
    18.             End If
    19.          .ActiveDocument.Bookmarks("type").Select
    20.          .Selection.Text = (txtSubject.Text)
    21.          .ActiveDocument.Bookmarks("people").Select
    22.          .Selection.Text = (txtPersons.Text)
    23.          .ActiveDocument.Bookmarks("action").Select
    24.          .Selection.Text = (rtbAction.Text)
    25.          .ActiveDocument.Bookmarks("From").Select
    26.          .Selection.Text = (gstrUserRealName)
    27.           If chkShowDoc.Value = vbChecked Then
    28.                 .Visible = True
    29.           Else
    30.                 .Visible = False
    31.           End If
    32.          .ActiveDocument.PrintOut Background:=True
    33.          .ActiveDocument.SaveAs FileName:=strFileName & ".doc"      
    34.          .Application.Documents.Close
    35.      End With
    36.  
    37.     Set ObjWord = Nothing
    38.  
    39. 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.

  2. #2

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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?

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

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

  5. #5

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Word SaveAs And Display On Screen

    That sounds cool. I'll give it shot.

    Thanks.!

  8. #8

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Word SaveAs And Display On Screen

    Does anyone know how to view Bookmarks that have been created within a Word document?

  9. #9
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Word SaveAs And Display On Screen

    You could try

    VB Code:
    1. Dim i As Integer
    2.   With objWord.ActiveDocument.Bookmarks
    3.     For i = 1 To .Count
    4.       MsgBox .Item(i).Name
    5.     Next i
    6.   End With
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  10. #10

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  11. #11
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Word SaveAs And Display On Screen

    Ok then this one instead

    VB Code:
    1. objWord.ActiveWindow.View.ShowBookmarks=True
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  12. #12
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    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.

    VB Code:
    1. Sub FileSave()
    2.  
    3.  
    4.  
    5. End Sub

    and

    VB Code:
    1. Sub FileSaveAs()
    2.  
    3.  
    4.  
    5.  
    6. End Sub

    Obviously at this point you would need to use the CommonDialog control to create your own Save method.

  13. #13
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  14. #14
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    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:
    1. objWord.ActiveDocument.CommandBars("File").Controls("Save").Enabled = False
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  15. #15
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    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:
    1. Sub FileSave()
    2.  
    3. msgbox "Intercepting the Save Command"
    4.  
    5. End Sub

  16. #16
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Word SaveAs And Display On Screen

    Hack

    Is this resolved then or did you forget about it?
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  17. #17

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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:
    1. Sub FileSave()
    2.  
    3. msgbox "Intercepting the Save Command"
    4.  
    5. 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

    Thanks for reminding me.

  18. #18
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: [RESOLVED] Word SaveAs And Display On Screen

    I don't give up on something until i know it's resolved..

    Sorry to be a pain..
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width