Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: How to append one graph to another


From   "Sebastian F. Büchte" <sfbuechte@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: How to append one graph to another
Date   Sat, 29 Sep 2007 16:56:14 +0200

Steve

to follow-up on my last message, I found some time today to write a
little "quick&dirty" (basically no documentation provided!)  vba
module (MS Word 2002) which allows you to select a path and afterwards
the program will paste all image files (*.tif, *.gif, *.png, *.jpg,
*.jpeg) into your current word document.

You will have to copy the following lines into a vba module of your
Word document and afterwards you have to run the macro named
"ImportImageDir". I hope this is helpful. Feel free to use, share and
copy it. Please note, you are using the vba program at your own risk.
I will take no responsibilty for any damage which could possibly arise
from using this vba program.

' copy from here
' macro to import all images from a selected path
' created with MS Word 2002
Sub ImportImageDir()
    Dim fd As FileDialog
    Dim fs As FileSearch
    ' ff holds all considered extensions for image files
    Dim ff As New Collection
    ff.Add ("tif")
    ff.Add ("jpg")
    ff.Add ("gif")
    ff.Add ("jpeg")
    ff.Add ("png")
    ' Create FileDialogObject for selection of Folder
    ' which contains the graphs for the multiple import
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
        .Title = "Please select folder for image file import..."
        .Filters.Delete (1)
        .Filters.Add "Images", "*.tif; *.png; *.gif; *.jpg; *.jpeg"
        If .Show() = -1 Then
            ' user chose folder and pressed "ok"
            Set fs = Application.FileSearch
            For Each ffilter In ff
                With fs
                    .LookIn = CurDir()
                    .FileName = "*." & ffilter
                    If .Execute(SortBy:=msoSortByFileName, _
                            SortOrder:=msoSortOrderAscending) > 0 Then
                        MsgBox "There were " & .FoundFiles.Count & " " & _
                                ffilter & "-file(s) found."
                        For i = 1 To .FoundFiles.Count
                            ' import all files of current extension
into word document
                            Selection.InlineShapes.AddPicture FileName:= _
                                    .FoundFiles(i), LinkToFile:=False, _
                                    SaveWithDocument:=True
                        Next i
                    Else
                        MsgBox "There were no " & ffilter & "-files found."
                    End If
                End With
            Next
        End If
    End With
End Sub
' end of copy

Regards
Sebastian

2007/9/28, Sebastian F. Büchte <sfbuechte@gmail.com>:
> Steve
>
> I guess you could -graph export- all graphs to an adequate format
> (e.g. png or tif) all into the same directory. Then you could write a
> "little" MS Word Visual Basic for Applications module which imports
> one file after the other from a given directory into you current Word
> document. Unfortunately, I am not that fit in writing Word  vba
> modules so I cannot provide you with a little piece of code.
>
> Having written the lines above, I just tried to paste multiple image
> files (all tif) into a document using the "Paste->Image->from file"
> functionality of MS Word. It worked for 10 images at a time. So you
> could -graph export- you Stata graphs all into one directory and then
> try to import multiple files into you Word document.
>
> Regards
> Sebastian
>
> 2007/9/28, sdm1@york.ac.uk <sdm1@york.ac.uk>:
> > I want to put 40 graphs, one below the other, into a Word document.  I can do this by drawing a
> > graph, then selecting, copying and pasting it into Word, and then repeating this 39 times.  But
> > there must (I hope) be a quicker way of doing this.  Suggestions please!
> >
> > Thanks.
> >
> > Steve
> >
> >
> > *
> > *   For searches and help try:
> > *   http://www.stata.com/support/faqs/res/findit.html
> > *   http://www.stata.com/support/statalist/faq
> > *   http://www.ats.ucla.edu/stat/stata/
> >
>

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index