Adapt an Excel macro to Word

J

Jean-Guy Marcil

Alberto said:
Hi,
I was hoping that someone could help me.
I have an Excel macro which creates a GIF file out of the the current
workbook, I was hopping to adapt that to Microsoft Word.
The macro can be seen below and is also attached, any suggestions?
Thanks in advance.

Macro here: http://homepage.ntlworld.com/trujillo/Excel_to_Gif.txt

First, you cannot make a single picture of all pages in the Word document.
At tbest, you can make one picture per page.
Second, there is no "Export" method in Word.
Also, do you need the headers/footers as well?

Here is your code, modfied to save the currently selected range as a picture
through the Save As HTML feature which will create a folder containing the
pictures from the document being saved.
____________________________________
Dim Carpeta As String
Dim Ruta As String
Dim NomArch As String
Dim NomGif As String
Dim docNew As Document

Carpeta = "C:\Docs\"
Ruta = Carpeta & "Año " & Year(Date) & "\"

NomArch = ActiveDocument.Name
NomGif = Left(NomArch, Len(NomArch) - 4) & ".gif"

If Dir(Ruta, vbDirectory) = "" Then MkDir Ruta

Selection.Range.CopyAsPicture

Set docNew = Documents.Add

docNew.Range.PasteSpecial DataType:=wdPasteDeviceIndependentBitmap
docNew.SaveAs Ruta & NomGif, wdFormatFilteredHTML
____________________________________
 
A

Alberto

Hi,
Thankyou very much for modifying the macro.
It was very useful, worked fine, the only exception being the line:
"docNew.Range.PasteSpecial DataType:=wdPasteDeviceIndependentBitmap"
That line gave an error which said that the object did not excist, so I just
changed it to:
"docNew.Range.PasteSpecial DataType:=wdPasteDefault"

Also, regarding whether I need headers/footers, this would be very useful,
do you know if its possible?

Again thankyou very much for your help.

A Trujillo
--
 
J

Jean-Guy Marcil

Alberto said:
Hi,
Thankyou very much for modifying the macro.
It was very useful, worked fine, the only exception being the line:
"docNew.Range.PasteSpecial DataType:=wdPasteDeviceIndependentBitmap"
That line gave an error which said that the object did not excist, so I just
changed it to:
"docNew.Range.PasteSpecial DataType:=wdPasteDefault"

Also, regarding whether I need headers/footers, this would be very useful,
do you know if its possible?

I believe it would be complicated.
Right now, all I can think of is to access the header, make a picture, paste
it in some document, access the footer, etc...

There might be an easier way, but right now I can't think of it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top