(Msg. 1) Posted: Tue Nov 03, 2009 4:05 pm
Post subject: Automate stuffing jpgs into Word, saving and exiting Archived from groups: microsoft>public>word>docmanagement (more info?)
Hi all,
To sum up, I'm just trying to automate stuffing jpgs into empty
documents, saving them and exiting.
I'm trying to create 3 documents ( templates?) where each executes a
macro on start-up that inserts a picture ( always the same name) and
saves the resulting document in a specific directory, again with a set
name. Word then should automatically close.
E.g.
rptcomp1.doc inserts comp1.jpg saves as c:\return\comp1.doc
rptcomp2.doc inserts comp2.jpg saves as c:\return\comp2.doc
rptcomp3.doc inserts comp3.jpg saves as c:\return\comp3.doc
The user opening one of these rptcomp documents would just see a flash
as Word opens and closes. The net result being that the return file is
generated. For what it's worth the jpg is a screenshot of a report from
another program. They want to see docs instead of jpgs for some reason.
The problem I'm facing is that I can't get the macros to autoexecute
even though they are called AutoExec. I also don't know if the starting
document should be a doc or a dot file. Also, when I'm writing the macro
I want to do an alt-file exit. That seems to abort the macro recording
prematurely and the resulting macro doesn't exit at the end like it's
supposed to. What I have now does the import and saves the file
correctly. Just doesn't start automatically or quit at the end.
Also I worry about the end product. I don't want the document file
that's eventually created to have a macro in it. Those people are
supposed to be able to see the JPG. That's the whole point of the
exercise.
(Msg. 2) Posted: Wed Nov 04, 2009 2:05 am
Post subject: Re: Automate stuffing jpgs into Word, saving and exiting [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
The following should work. Save the following macro in document template
(dotm template in Word 2007) . Change the path to that where the images are
stored. Double click the filename from Windows Explorer to open Word and run
the macro which will create the three documents where indicated and then
quit Word.
Sub AutoNew()
Dim DocA As Document
Dim DocB As Document
Dim DocC As Document
Dim sPath As String
'Define path containing the pictures
sPath = "D:\My Documents\My Pictures\"
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
Application.ScreenUpdating = False
Set DocA = Documents.Add
Set DocB = Documents.Add
Set DocC = Documents.Add
DocA.Range.InlineShapes.AddPicture FileName:= _
sPath & "Comp1.jpg", LinkToFile:=False, _
SaveWithDocument:=True
DocA.SaveAs "c:\return\comp1.doc"
DocB.Range.InlineShapes.AddPicture FileName:= _
sPath & "Comp2.jpg", LinkToFile:=False, _
SaveWithDocument:=True
DocB.SaveAs "c:\return\comp2.doc"
DocC.Range.InlineShapes.AddPicture FileName:= _
sPath & "comp3.jpg", LinkToFile:=False, _
SaveWithDocument:=True
DocC.SaveAs "c:\return\comp3.doc"
Documents.Close
Application.ScreenUpdating = True
Application.Quit
End Sub
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
Pete Dixon wrote:
> Hi all,
>
> To sum up, I'm just trying to automate stuffing jpgs into empty
> documents, saving them and exiting.
>
> I'm trying to create 3 documents ( templates?) where each executes a
> macro on start-up that inserts a picture ( always the same name) and
> saves the resulting document in a specific directory, again with a set
> name. Word then should automatically close.
>
> E.g.
>
> rptcomp1.doc inserts comp1.jpg saves as c:\return\comp1.doc
> rptcomp2.doc inserts comp2.jpg saves as c:\return\comp2.doc
> rptcomp3.doc inserts comp3.jpg saves as c:\return\comp3.doc
>
> The user opening one of these rptcomp documents would just see a flash
> as Word opens and closes. The net result being that the return file is
> generated. For what it's worth the jpg is a screenshot of a report
> from another program. They want to see docs instead of jpgs for some
> reason.
>
> The problem I'm facing is that I can't get the macros to autoexecute
> even though they are called AutoExec. I also don't know if the
> starting document should be a doc or a dot file. Also, when I'm
> writing the macro I want to do an alt-file exit. That seems to abort
> the macro recording prematurely and the resulting macro doesn't exit
> at the end like it's supposed to. What I have now does the import and
> saves the file correctly. Just doesn't start automatically or quit at
> the end.
>
> Also I worry about the end product. I don't want the document file
> that's eventually created to have a macro in it. Those people are
> supposed to be able to see the JPG. That's the whole point of the
> exercise.
>
> Any suggestions gratefully received.
All times are: Eastern Time (US & Canada) (change)
Page 1 of 1
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum