I need to add a feature onto an existing Word macro

I use Microsoft Outlook 2007 in a Windows 7 operating environment.

I am attaching a Word Macro that an expert exchange member was kind enough to develop in order to accomplish what I wanted to do. Generally, I create 80 page Word documents, the first 10 pages are comprised of text and a few images; while the last 5 pages consist of text. All the pages in between consist of images.

The Word Macro which was designed, allows me to designate a folder, usually containing hundreds of images, and the macro inserts them into successive blank pages in a 3 row by 2 column format. Since I'm using this more and more, the issues I am running into now involve the increasing difficulty of simply doing a cut-and-paste of the 50-60 pages of images from the resulting new Word document and insert it into my primary document with the text.

I've enclosed the macro in hopes that there was a way that I could instruct it to start loading the images in a specific existing document, starting at a particular page number; rather than start a blank new document every time it does it.

Thank you very much for your help and pity taken on a non-coding macro neophyte.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

have you ever thought about investing some time and money into a proper desktop publishing solution with some workflow automation plug-ins?

I'm thinking something like Quark Xpress or Adobe InDesign with some automation would give you much better and quicker results - and it's designed from the ground up for that kind of workflow.
photoman11Author Commented:
Actually I have, however I am dealing with so many applications already (over 60 at last count), the thought of taking on anything more complicated than tic-tac-toe, is met with high blood pressure.

So this point, I'm just hoping for a slight revision to the Word Macro.
roylong has a point. However, if you want to add VBA to your skills, it's good to have a starting point.

Here is some modified code
Sub InsertPicturesInTables()
    Dim Doc As Word.Document
    Dim tbl As Word.Table
    Dim strFolder As String
    Dim strFileName As String
    Dim c As Integer
    Dim r As Integer
    Dim ilsh As InlineShape
    Dim iPage As Integer
    Rem this is a whole-line comment (REM is short for remark)
    'and so is this. To append a comment following code on a line you must use the apostrophe and not REM
    strFolder = "F:\Images for Word Macro" 'edit this to match your folder
    Set Doc = ActiveDocument 'Documents.Open("C:\MyDocs\MyFile.doc") 'Open the document
    iPage = 10 'say
    If iPage > Doc.Range.Information(wdNumberOfPagesInDocument) Then
        MsgBox "Page " & iPage & " doesn't exist"
        Selection.GoTo wdGoToPage, wdGoToAbsolute, iPage
        Set tbl = Doc.Tables.Add(Doc.Bookmarks("\Page").Range, 3, 2) 'create a 3-row, 2-column table
        tbl.Rows.HeightRule = wdRowHeightExactly
        tbl.Rows.Height = CentimetersToPoints(7)
        tbl.Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter 'centre cell content vertically
        tbl.Range.Paragraphs.Alignment = wdAlignParagraphCenter 'inline shapes are treated like text.
        strFileName = Dir$(strFolder & "\*.jpg") ' find the first file in the folder
        c = 0
        r = 1
        Do Until strFileName = ""
            c = c + 1 'c is used to set the column number
            If c = 3 Then
                r = r + 1
                If r = 4 Then
                    Doc.Bookmarks("\EndOfDoc").Range.InsertBreak wdPageBreak
                    Set tbl = Doc.Tables.Add(Doc.Bookmarks("\EndOfDoc").Range, 3, 2) 'create a 3-row, 2-column table
                    tbl.Rows.HeightRule = wdRowHeightExactly
                    tbl.Rows.Height = CentimetersToPoints(7)
                    tbl.Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter 'centre cell content vertically
                    tbl.Range.Paragraphs.Alignment = wdAlignParagraphCenter 'inline shapes are treated like text.
                    r = 1
                End If
                c = 1
            End If
            Debug.Print r, c, strFileName
            Set ilsh = Doc.InlineShapes.AddPicture(strFolder & "\" & strFileName, False, True, tbl.Cell(r, c).Range)
            strFileName = Dir$()
    End If
End Sub

Open in new window

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

photoman11Author Commented:

I appreciate your point as well as Roy's. Truth be told, I never understood programming although I tried 3 times and it is far too frustrating and overwhelming at this point to even consider it. I try to stay away from it like the plague, but unfortunately I am not always successful.

Since I don't understand it, it's hard for me to even ask semi-intelligent questions about it. So I've decided to take a different tact and plead complete ignorance, and list a few questions that you might consider answering:

All of these are based on the assumption that the above 52 lines of code are meant to replace my current macro and to accomplish everything it did, PLUS to insert the images into an existing document rather than start a new document...

1. I am guessing that line #14 has something to do with identifying which document, the images are supposed to be inserted into, and where in the document (page number). I am sure if I take a guess on how to change this, to match my drive and directory structures, I will mess it up completely.

Instead, how about if I just tell you that the document that I want to run the macro for, will be open on my desktop at this path: C:\Users\Dinny\Desktop\[name of document.docx]

Therefore, can that information be inserted into the proper place, in the code?

2. Can you tell me where in the code I identify the page number where I want the images to start being inserted into?

I guess that is about it. I place the images in a folder ("F:\Images for Word Macro") and all I am trying to figure out now is how to tell the macro where the document is located that I want the images loaded into.

And, should the document be open or not.

Thanks for your help and understanding area
If you need to use VB code, you will have to learn something about how to use it. You already know where a VBA macro goes and how to start it.

This site is intended to be one that gives tips -  not to do all your development . It is arguable that I exceeded that remit with the original macro, but I couldn't find an example that demonstrated the methods that you needed. The macro is now there for anyone else who needs to do anything like that.

Yes the macro is a replacement.

As it stands, Line 14 sets the active document that is already open in the application as the one to work on.  

The commented out part shows how it could be used to open a particular file, thus:

Set Doc = Documents.Open("C:\MyDocs\MyFile.doc") 'Open the document

If you are always working on the same document, you can safely put the path in place of the bit within the quotes. If that file is already open, it will still work.

Line 15 hard-codes the number of the page that you want to accept the data.

Using page numbers for navigation in Word is generally problematic. Page numbers can change, but this will be OK if the earlier parts of the document are fixed.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
photoman11Author Commented:
I understand you going above and beyond. And, please realize that I am very appreciative and do not expect development work to be done. Actually, I wanted to know if the current code was in such a condition that I could use it as is or I needed to offer it as a starting point to somebody who I can pay to finish it.

I did want to come across as a total idiot, offering to pay someone to finish something that already was finished. Keeping in the spirit of Expert Exchange, what is your opinion on accessing resources who could perform visual basic tasks like this?

Within the expert pool on this site? I have used oDesk before for a variety of tasks, but not Visual Basic. Or, would you recommend a different source to assist in this manner?

Thanks again for everything!
Sorry. I missed the questions in your final comment.

Some of the experts here do offer paid help with projects that are too large to be considered as questions. Those that do will indicate this and will have a contact address in their profiles.

Personally I don't know anything about oDesk, but I think that this is the right place for VB and VBA questions.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.