Results 1 to 6 of 6
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trapping .saveAs formats (and other) (WordXP)

    How can I trap/obtain data such as the proposed-save format from a dialogue box and translate it into an appropriate parameter?
    In the code below, dial.Name is a no-brainer, but the dial object is lean compared to the saveAs method.
    I am using 'format' as an example; there are other properties that suffer the same fate.
    And even for format, checking the extent is no solution, since I might want to save in TEXT format with an extent of LOG.


    When I record the process of saving a file in (say) HTML format, I see the following code:
    <pre> ActiveDocument.SaveAs FileName:="Doc8.htm", FileFormat:=wdFormatHTML, _
    LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
    :="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
    SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
    False</pre>

    The item "FileFormat:=wdFormatHTML" seems to be causing the document to be saved in a web format.
    But when I look at the code that drives the SaveAs dialog, I see no item in the "dial" object that allows me to obtain the appropriate format.
    The property .Type seems to be irrelevant here, and the Help files for "Format" and "Type" certainly don't correspond. <pre> Dim dial As Dialog
    Set dial = Dialogs(wdDialogFileSaveAs)
    dial.Name = ActiveDocument.Name
    If dial.Display = -1 Then
    ActiveDocument.SaveAs FileName:=dial.Name
    Else
    End If</pre>


  2. #2
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trapping .saveAs formats (and other) (WordXP)

    Hi Chris

    Not quite sure what your objective is here, but this code at least seems consistent in terms of displaying and setting the file format to that specified in the macro:
    <code>
    Sub tst()
    Dim dial As Word.Dialog
    Set dial = Dialogs(wdDialogFileSaveAs)

    With dial
    .Name = ActiveDocument.Name
    .DefaultTab = .Format
    .Format = wdFormatHTML '= 8
    If .Display = -1 Then
    ActiveDocument.SaveAs FileName:=dial.Name
    Else
    End If
    End With

    End Sub
    </code>
    Alan

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trapping .saveAs formats (and other) (WordXP)

    Alan thanks for this response.
    I hijack the document-save event, and determine that the user wants to bypass our awfully clever naming scheme, and drop to the native File,saveAs dialogue. Of course, I want to remain in control.

    I can execute the dialogue box ("dial") and retrieve the .Name, but now the user wants to play around with Tools, and set the password. And the user wants to save the DOCument as, say, an RTF file.

    I can't see how I can obtain that RTF format setting from my "dial" object.

    dial.Type is not the same value set as Format (as in RTF, TXT, HTML). Further, I can't use the extent as a guide, because I can't prohibit the user from doing anything Chris Greaves would do at home, i.e. save a text-format file with an extent of, say, .LOG.

    Your example is good, but it relies on a hard-coded ".Format = wdFormatHTML '= 8".

    Sample question: How would you go about obtaining that value as ".Format = .dial.?????"

    Sample question: How would you go about obtaining all the other stuff such as Security ".Format = .dial.?????"

    I'm not too concerned with general-purpose settings (Add to favorites etc). Users are on their own with that - although - I already have code to deal with that stuff, two MRU handlers for files and the AddtoMyPlaces. If I *could* hijack those from the saveAs dialogue box I could splice in my own utility code.

    Main thing is the file type and security. I can't see me being able to obtain those from the "dial" object.

  4. #4
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trapping .saveAs formats (and other) (WordXP)

    Chris

    The properties of the dialog, such as .Format are read/ write, so you can retrieve as well as set them. Try this modified code.
    <div style="width: 100%; background-color: #FFFFFF;"><code><font color=black>
    <font color=blue>Sub</font color=blue> tst()
    <font color=blue>Dim</font color=blue> msg <font color=blue>As</font color=blue> <font color=blue>String</font color=blue>
    msg = "0 (zero)" & vbTab & "Word document" & vbCrLf _
    & "1" & vbTab & "Document template" & vbCrLf _
    & "2" & vbTab & "Text Only (extended characters saved in ANSI character set)" & vbCrLf _
    & "3" & vbTab & "Text Only with Line Breaks (extended characters saved in ANSI character set)" & vbCrLf _
    & "4" & vbTab & "MS-DOS Text (extended characters saved in IBM

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trapping .saveAs formats (and other) (WordXP)

    Alan, thanks for both the sample (worked flawlessly) which allows me to satisfy an immediate call for formatted saves, and for the help file, which I have duly d/l and will explore this evening.

  6. #6
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trapping .saveAs formats (and other) (WordXP)

    Glad it's working for you Chris. I found the mechanics of Office dialogs a bit obscure at first, perhaps because of the disjoint and relatively lean documentation. I think the combination of the VBA and WordBasic help files, together with the (many) code examples here in the Lounge, eventually set me straight on these.

    Alan

Posting Permissions

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