Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Sep 2002
    Location
    Princeton, New Jersey, USA
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Automating Insertion of Graphics

    When manually inserting a postscript (.ps) file (via Insert: Picture: from File) for the first time, a dialog box pops up, asking you to choose the Graphics Filter to use. I select Encapsulated Postscript. For the remainder of the Word session, you can insert .ps files without this dialog box appearing. If you close Word and then launch a new session, the dialog box pops up again (only for the first insertion).

    I have written a macro that will automatically insert these .ps files from a user-specified directory into a new Word document. My problem is that when you run the code in a session of Word where you've never specified the graphics filter, it bombs because it doesn't know what graphics filter to use. However, I can't figure out how to tell the code which filter to use. I've tried the simple approach of recording these steps via the macro recorder, but no code regarding the graphics filter is recorded. I've also searched VBA help and haven't found anything. Here's the portion of the code that's inserting the .ps files (the filenames & path have already been stored in the "stPics" array). The code hits the error trap when running during a session of Word where I haven't inserted a .ps file manually and specified the graphics filter. Any help would be greatly appreciated!

    For iCounter = 1 To UBound(stPics)
    If stPics(iCounter) <> "" Then
    On Error GoTo errtrap
    Set shPic = Selection.InlineShapes.AddPicture(Filename:=stPics (iCounter))
    Selection.TypeParagraph
    End If
    Next
    Exit Sub

    errtrap:
    MsgBox Title:="Error", buttons:=vbOKOnly + vbCritical, Prompt:= _
    "Sorry. An error has stopped the execution of ScanToWord." & vbLf & vbLf & _
    "Please contact an administrator."
    Exit Sub
    End Sub

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Automating Insertion of Graphics

    As a kludge, you could do the following when the iCounter = 1:

    With Dialogs(wdDialogInsertPicture)
    SendKeys stPics(iCounter) & "{ENTER}"
    .Show
    End With

    I haven't tested with an array, but using a file name does pop up the Converter dialog if the format isn't immediately recognized. (Of course, any suggestion to use SendKeys comes with the usual disclaimer that it can be unreliable!)

  3. #3
    New Lounger
    Join Date
    Sep 2002
    Location
    Princeton, New Jersey, USA
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automating Insertion of Graphics

    Thank you, I tried what you suggested but didn't have any luck. A variation does sort of work: displaying the dialog box when iCounter = 1 and letting the user "manually" insert the first image, which forces the Converter dialog to display. (Of course, then they have to know the name of the first image so they can navigate to it; the files are inserted in the order that is specified in a separate text file.) Sure wish there was a way to display the Converter dialog via code, or hard code in which graphics filter to use!

    Thanks again for your help!

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Automating Insertion of Graphics

    If you insert a graphic using the includepicture field, you are able to include a switch to specify the filter used. What if you reset the code to bring in the graphic using the includepicture field and then break the field (if you wanted to).
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    New Lounger
    Join Date
    Sep 2002
    Location
    Princeton, New Jersey, USA
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automating Insertion of Graphics

    Thanks, Andrew. That sounds like a great idea! I'll give it a try.

Posting Permissions

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