• Saving as a GIF (VBA Word 2000)

    • This topic has 16 replies, 8 voices, and was last updated 17 years ago.
    Author
    Topic
    #368231

    Is there a way to create a macro that will select a block of text and save as a .gif?

    I need to take a list of words or phrases, say in a table or just one word/phrase per paragraph, and save each one as a .gif file. Is there a way to do this with VBA?

    Thanks!!
    Troy

    Viewing 2 reply threads
    Author
    Replies
    • #576398

      Hi Troy,

      (I always respond to posts that feature my initials!)
      Hate to go against the ‘never say die’ grain here, but this sounds virtually impossible to do via VBA. When you select text in the text layer, what is being selected is basically a text string (with whatever formatting may be linked to it), rather than a picture of something that can be saved to a graphics format.

      Neither does any office app allow you save a file as a .gif (that I know of) – so you can’t create a new file containing just the selected text and save as .gif.

      You may need to find a different way to get done what you need to do….

      Gary

      • #576436

        One way is to select the text and the Print the selection as a PDF file.

        You can then open the PDF file in Acrobat and save it as, say, JPG or PNG.

        Then use some drawing tool such as Photo Editor to save as GIF.

        • #576448

          What version of Acrobat allows that? I have Acrobat 4.05 and cannot find the capability to save as a jpg.

          Also, can it do that as a batch job? If so, I think I’d be home free. I could automate saving the selection as a pdf, batch the pdfs to jpg, and then use Paintshop Pro to batch the jpgs to gifs.

          Thanks for your help!!
          Troy

      • #579293

        PowerPoint (I checked this in 2002) allows you to Save As a .gif.

        • #579546

          Hi Margot,

          Thanks very much for straightening me out on this – I’d never bothered to look – but you can save PPTs as .gifs, .jpgs, .wmfs and a bunch of other nice things. thumbup

          Best of all, this means that Troy’s request actually is doable; I’m happy to contradict my original reply ’cause this is a sweet little macro: groovin

          Public Sub SaveWordPhraseAsGIFViaPPT()
          'Gary Frieder  Woody's Lounge  March 2002
          'Purpose: For each paragraph in a Word document,
          'saves the text as a GIF (via PowerPoint)
          'Assumes a reference has been set to PPT library
          Dim DocParas As Paragraphs
          Dim strPhrase As String
          Dim n As Long
          Dim PPT As PowerPoint.Application
          Dim TempPres As PowerPoint.Presentation
          Dim TempSlide As PowerPoint.Slide
          Set PPT = New PowerPoint.Application
          
          Set DocParas = ActiveDocument.Paragraphs
          For n = 1 To DocParas.Count
              strPhrase = DocParas(n).Range.Text
              Set TempPres = PPT.Presentations.Add
              Set TempSlide = TempPres.Slides.Add(1, ppLayoutText)
              TempSlide.Shapes(2).Delete
              TempSlide.Shapes(1).TextFrame.TextRange.Text = strPhrase
              TempPres.Export "C:TempWord Phrase #" & n, "GIF"
              TempPres.Close
          Next 'n
          
          PPT.Quit
          
          Set DocParas = Nothing
          Set TempPres = Nothing
          Set TempSlide = Nothing
          Set PPT = Nothing
          
          End Sub
          

          Thanks again,
          Gary

          • #580064

            I do like that macro. I may never *need* it, but I made a copy of it just in case!!! Ran just fine. Plus it may come in handy as a “go-by” if I ever want to open PowerPoint from Word.

          • #1105913

            >this is a sweet little macro:
            I might say that.
            It’s sweeter still as a little function that harvests inline shapes from within a document.
            THANKS!

            • #1106181

              I haven’t quite worked this out, but FWIW:
              I’m converting a set of WPD via RTF to DOC, then extracting images from within the DOC.
              My code gets to the line

              TempPres.Export strNewName, "JPG"

              and then baulks with “Presentation (unknown member) failed”, a.k.a. Run-time error -2147467259.
              The value of strNewName at this point is

              J:20080331EnglishADMADM-PGW153I.WPD.DOC.JPG

              If I lop off extraneous extents and use

              strNewName="J:20080331EnglishADMADM-PGW153I.JPG"

              then the slide/image is saved flawlessly!

    • #576405

      I could imagine, but not code, the following:

      (1) Determine the screen coordinates of the selection.
      (2) Using something in the Windows API, capture that portion of the screen.
      (3) Run some graphical toolkit to change from whatever the native format is to GIF.

      While it is tempting to think about a print screen, SendKeys cannot access the PrintScreen button, so the usual shortcuts don’t appear to be available.

      Also, all the colors would be backwards if the text was selected. Hmmm…

      There probably is some software out there, akin to WordArt, that can save as GIF, but whether it can be automated…

    • #1106194

      >Is there a way to create a macro that will select a block of text and save as a .gif?
      See also this thread post 706,955 (19 April 2008) for saving an image from the clipboard to a gif/jpg file.

      • #1106230

        Hi Chris,

        Take a look at the zip file here:http://www.lebans.com/msword.htm%5B/url%5D It seems to me that it would be quite straightfoward to use this in conjunction with the CopyAsPicture and PasteSpecial (DataType)methods to convert a range to an image.

        Cheers,
        Paul Edstein
        [Fmr MS MVP - Word]

        • #1106260

          >to convert a range to an image.
          Paul, thanks for adding this to my arsenal. It is a great deal neater than my kludge.
          It works well, but saves as BMP/EMF, whereas I need JPG.
          I’ll go with my current kudgy solution to “get the immediate job done”

          • #1106276

            Here is my (stolen from The Lounge!) code which ran well:

                    ' Build the JPG file from the clipboard
                    ''' You need a reference to the Microsoft Excel Object library.
                    Dim xl As Excel.Application
                    Set xl = CreateObject("excel.application")
                    xl.Visible = True
                    xl.Workbooks.Open ("J:ConversionMakeGIFChrisGreavesMakeGIF.xls")
                    xl.DisplayAlerts = False
                    xl.Quit
                    ' Obtain a valid name
                    ' blah blah blah 
    Viewing 2 reply threads
    Reply To: Saving as a GIF (VBA Word 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: