|
-
Aug 11th, 2011, 09:39 AM
#1
Thread Starter
New Member
Looking for assistance with pictures and tables
Development: Word 2010
Use: Word XP, 2007, 2010
Objective: Create vba/macro that will resize all photos and then create an individual table to place each photo into.
The photos will be drag/drop placed into the blank Word Template, at the size created by a digital camera. I have the code for resizing all of the photos (or shapes and inlineshapes). This photo placement and resizing happens only once.
After all of the photos are resized, I need to create or insert a table for each photo and then move each photo into the first cell of each table. End result is that each photo is framed in a table.
Each table is complex and includes form elements.
Currently, I am inserting the table from another word file using a macro.
I have the code for bringing in the table.
I am needing help with the code for selecting a photo, cutting the photo, inserting the table, pasting the cut photo into the first cell of the inserted table, move to next photo and repeat until all photos are framed in a table.
The code I am using now is:
Resize photos:
Code:
Sub TestPicResize()
'
' TestPicResize Macro
'
'
Dim NewPhotoSize As Integer
Dim OneShp As InlineShape
Dim TwoShp As Shape
'2 is the inch count multiplied by the point scale
NewPhotoSize = 2 * 72
If Err.Number = 13 Then GoTo 10
For Each OneShp In ActiveDocument.InlineShapes
With OneShp
.Height = NewPhotoSize
.LockAspectRatio = msoTrue
End With
Next OneShp
For Each TwoShp In ActiveDocument.Shapes
With TwoShp
.Height = NewPhotoSize
.LockAspectRatio = msoTrue
End With
Next TwoShp
10
End Sub
Insert Table from External File
Code:
Sub Insert_Picture_Table()
'
' Insert_Picture_Table Macro
'
'
Dim zPath As String
' Dim DirPathOne As String
' Dim DirPathTwo As String
zPath = Environ("UserProfile") 'Get C:\Users\username
' Windows 2007 or 2010 path
' DirPathOne = zPath & "\Documents\CompRigInspForm\Resource\"
' Windows XP path
' DirPathTwo = zPath & "\My Documents\CompRigInspForm\Resource\"
On Error GoTo ErrHandler
ChangeFileOpenDirectory _
zPath & "\Documents\CompRigInspForm\Resource\"
Selection.InsertFile FileName:="picTable2.dotm", Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
GoTo AllDone
ErrHandler:
MsgBox "You Improperly installed the root files, or you are using Windows XP. Contact ... for assistance."
AllDone:
End Sub
As you can see from the comments in the insert table code, I am also looking for a solution to the XP "My Documents" vs the 2007 and 2010 "Documents" difference, so that if a "Documents" folder doesnt exist, then try a "My Documents" folder before presenting error message.
I am thinking that inserting the table and placing the picture can be squished into the resize photo code, so for each photo the following occurs:
1. a photo is resized
2. a table is inserted at the bottom of the document.
3. resized photo is placed in the first cell of the table at the bottom of the document.
4. process is repeated for each photo.
5. process ends
So, could anyone assist me with tieing all of this together?
-
Aug 11th, 2011, 01:47 PM
#2
Hyperactive Member
Re: Looking for assistance with pictures and tables
Hi JoeyL,
I cannot help you with your main problem, most of my VBA skills are with Excel and Access,
however I suggest you try the following
Code:
DirPath = Options.DefaultFilePath(wdDocumentsPath) & "\CompRigInspForm\Resource\"
Options.DefaultFilePath allows you to retrieve a number of different paths,
the wdDocumentsPath gives me the My Documents path, and I presume
would give the equivalent Documents path for Windows 2007 and 2010
Signature Under Construction 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|