PC Review


Reply
Thread Tools Rate Thread

2 ? macro - insert a table one line below a bookmark & Pics to tab

 
 
=?Utf-8?B?bW9wZ2N3?=
Guest
Posts: n/a
 
      27th Sep 2007
I have the following macro to insert a table into a word document at a
bookmark.

I need to re-use this bookmark to insert other information in a loop, so
once the table "takes-over" the book mark, the information following is all
put in the table, which is a mess.

How do i insert the table one line below the bookmark, thus keeping the
bookmark free to insert the other information?

And secondly, how do I insert the two jpgs to the table, as opposed to the
bookmark?

Appreciate any help.

Thanks
george

Here is the code:

'Copy the 1st table from the Excel Sheet IC MEMO

Range("ic_memo2").Copy

'Open IC Memo in Word

With ActiveDocument
If .Bookmarks.Exists(bookmarkname1) Then

.Bookmarks(bookmarkname1).Range.PasteSpecial Link:=True,
DataType:=wdPasteOLEObject, _
Placement:=wdInLine, DisplayAsIcon:=False

.Bookmarks(bookmarkname1).Range.InsertParagraph
.Bookmarks(bookmarkname1).Range.InsertParagraph
.Bookmarks(bookmarkname1).Range.InsertParagraph

For Each oShape In ActiveDocument.InlineShapes
With oShape
.LockAspectRatio = msoTrue
.Width = CentimetersToPoints(14.68)
.Height = CentimetersToPoints(6.77)
End With
Next oShape

Dim prange As Word.Range

Set prange = ActiveDocument.Bookmarks(bookmarkname1).Range

ActiveDocument.Tables.Add Range:=prange, NumRows:=1,
NumColumns:=2, _
DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed

Set ilsPic =
ActiveDocument.InlineShapes.AddPicture(Filename:=ic_photo1, _
LinkToFile:=False, SaveWithDocument:=True, _
Range:=prange)

.Bookmarks(bookmarkname1).Range.InsertParagraph

Set ilsPic =
ActiveDocument.InlineShapes.AddPicture(Filename:=ic_photo2, _
LinkToFile:=False, SaveWithDocument:=True, _
Range:=prange)

Dim pShape As InlineShape

For Each pShape In ActiveDocument.InlineShapes
With pShape
.LockAspectRatio = msoTrue
.Width = CentimetersToPoints(4.68)
.Height = CentimetersToPoints(6.77)
End With
Next pShape

.Save
Else
MsgBox "Bookmark: " & bookmarkname1 & " not found."
End If
End With

Windows(collatfile).Activate

Range("ic_memo1").Copy

'Open IC Memo in Word

With ActiveDocument

If .Bookmarks.Exists(bookmarkname1) Then

.Bookmarks(bookmarkname1).Range.PasteSpecial Link:=True,
DataType:=wdPasteOLEObject, _
Placement:=wdInLine, DisplayAsIcon:=False

.Bookmarks(bookmarkname1).Range.InsertParagraph
.Bookmarks(bookmarkname1).Range.InsertAfter (stext3) + Chr(13)
.Bookmarks(bookmarkname1).Range.InsertParagraph
.Bookmarks(bookmarkname1).Range.InsertAfter (stext2) + Chr(13)
.Bookmarks(bookmarkname1).Range.InsertParagraph
.Bookmarks(bookmarkname1).Range.InsertAfter (stext1) + Chr(13)
.Bookmarks(bookmarkname1).Range.InsertParagraph

Dim oShape2 As InlineShape
For Each oShape2 In ActiveDocument.InlineShapes
With oShape2
.LockAspectRatio = msoTrue
.Width = CentimetersToPoints(14.68)
.Height = CentimetersToPoints(6.77)
End With
Next oShape2

.Save
Else
MsgBox "Bookmark: " & BookMarkName2 & " not found."
End If
End With

' ================================
' go to collateral file and close
' ================================

Range("A1").Copy ' JUST TO CLEAR CLIPBOARD

Windows(collatfile).Activate

ActiveWorkbook.Close savechanges:=False

end If
Next Collatloop

Set wdapp = nothing

end sub

 
Reply With Quote
 
 
 
 
=?Utf-8?B?bW9wZ2N3?=
Guest
Posts: n/a
 
      27th Sep 2007
I updated the code as follows, but get an error code 450 too many arguments
or wrong properties at the add tables part....

here is the update:


'Copy the table from the Excel Sheet IC MEMO

Range("ic_memo2").Copy

'Open IC Memo in Word

With ActiveDocument
If .Bookmarks.Exists(bookmarkname1) Then

.Bookmarks(bookmarkname1).Range.PasteSpecial Link:=True,
DataType:=wdPasteOLEObject, _
Placement:=wdInLine, DisplayAsIcon:=False

.Bookmarks(bookmarkname1).Range.InsertParagraph
.Bookmarks(bookmarkname1).Range.InsertParagraph
.Bookmarks(bookmarkname1).Range.InsertParagraph

For Each oShape In ActiveDocument.InlineShapes
With oShape
.LockAspectRatio = msoTrue
.Width = CentimetersToPoints(14.68)
.Height = CentimetersToPoints(6.77)
End With
Next oShape

Dim prange As Word.Range

Set prange = ActiveDocument.Bookmarks(bookmarkname1).Range

With ActiveDocument
.Goto what:=wdGoToBookmark, Name:=bookmarkname1
Word.Selection.MoveDown Unit:=wdLine, Count:=1

ActiveDocument.Tables.Add Range:=Selection.Range,
NumRows:=1, NumColumns:=2, _
DefaultTableBehavior:=wdWord9TableBehavior,
AutoFitBehavior:= _
wdAutoFitFixed

With Selection.Tables(1)
.Columns.PreferredWidth = CentimetersToPoints(8)

If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If

.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With

Set ilsPic = ActiveDocument.InlineShapes.AddPicture
(Filename:=ic_photo1, _
LinkToFile:=False, SaveWithDocument:=True, _
Range:=Selection.Range)

Selection.MoveRight Unit:=wdCharacter, Count:=1

Set ilsPic =
ActiveDocument.InlineShapes.AddPicture(Filename:=ic_photo2, _
LinkToFile:=False, SaveWithDocument:=True, _
Range:=Selection.Range)

'Dim pShape As InlineShape

'For Each pShape In ActiveDocument.InlineShapes
'With pShape
' .LockAspectRatio = msoTrue
'.Width = CentimetersToPoints(4.68)
'.Height = CentimetersToPoints(6.77)
'End With
'Next pShape

End With

.Save
Else
MsgBox "Bookmark: " & bookmarkname1 & " not found."
End If
End With

Windows(collatfile).Activate

Range("ic_memo1").Copy

'Open IC Memo in Word

With ActiveDocument

If .Bookmarks.Exists(bookmarkname1) Then

.Bookmarks(bookmarkname1).Range.PasteSpecial Link:=True,
DataType:=wdPasteOLEObject, _
Placement:=wdInLine, DisplayAsIcon:=False

.Bookmarks(bookmarkname1).Range.InsertParagraph
.Bookmarks(bookmarkname1).Range.InsertAfter (stext3) + Chr(13)
.Bookmarks(bookmarkname1).Range.InsertParagraph
.Bookmarks(bookmarkname1).Range.InsertAfter (stext2) + Chr(13)
.Bookmarks(bookmarkname1).Range.InsertParagraph
.Bookmarks(bookmarkname1).Range.InsertAfter (stext1) + Chr(13)
.Bookmarks(bookmarkname1).Range.InsertParagraph

Dim oShape2 As InlineShape
For Each oShape2 In ActiveDocument.InlineShapes
With oShape2
.LockAspectRatio = msoTrue
.Width = CentimetersToPoints(14.68)
.Height = CentimetersToPoints(6.77)
End With
Next oShape2

.Save
Else
MsgBox "Bookmark: " & BookMarkName2 & " not found."
End If
End With

' ================================
' go to collateral file and close
' ================================

Range("A1").Copy ' JUST TO CLEAR CLIPBOARD

Windows(collatfile).Activate

ActiveWorkbook.Close savechanges:=False

End If

Next Collatloop

'Release Word object
Set wdApp = Nothing

MsgBox ("IC Memo from " + WorksheetFunction.Text(collatincluded, "0") + "
collateral files populated for Francis")

End Sub


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Insert 50 items from one table into a text box line by line Gregory A. Beamer Microsoft ASP .NET 0 14th Aug 2009 04:16 PM
Macro to insert line Lady Success Microsoft Excel Worksheet Functions 0 19th May 2009 04:23 AM
insert a line via macro Don Microsoft Excel Misc 3 28th Jun 2008 12:30 AM
Macro Line Insert =?Utf-8?B?RnJhbnRpYyBFeGNlbC1lcg==?= Microsoft Excel Misc 4 20th Mar 2006 11:08 PM
Pics/Clips insert/select from sql2000 table using c# =?Utf-8?B?QmVhdSBQZWVw?= Microsoft C# .NET 0 13th Jan 2006 04:25 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:42 PM.