I know Excel VBA programming very well but nothing about VBA in Word. I have a lot of content stored in Excel. The content is stored database-style, where a record is a row and the columns contain specific data. Some of the data stored in cells are entire paragraphs and some are path names to images. I wish to display all of this information to word. I have no problem accessing any of my data in Excel. Nor do I have any problems opening a new Word object and adding text and pictures. My problem is that I don't know anything about formatting images in word.
My question is: Through Excel, how can I insert an entire paragraph of text, then insert a small picture, aligned right, with the text from the paragraph wrapped around it?
After getting the word object and setting up a new Word document "word_doc"....right now I've got:
'// using word and excel 2007
With word_doc
.Content.InsertParagraphAfter
.Content.InsertAfter ("Sample text to start things off. This text should be long enough to take up several lines in a normal Word document. I don't know if I need to insert the picture before or after this text. At any rate this text should be on the left and a picture should be inserted on the right side of the word document with this text wrapped around it. I have no fixed location where this might be. It might be on the 2nd page of the Word document that i am creating and it might be on the 10th page.")
'// this is where I set the range as the last paragraph inserted.
'// again, this is where I don't know how to navigate around in Word through VBA
Set text_range = .Range(Start:=.Paragraphs(.Paragraphs.Count).Range.Start, End:=.Paragraphs(.Paragraphs.Count).Range.End)
text_range.ParagraphFormat.Alignment = wdAlignParagraphLeft
'// I have the picture link for the line below
Set word_image = text_range.InlineShapes.AddPicture("C:....", False, True)
max_h = 100
With word_image
orig_h = .Height
orig_w = .Width
r = orig_h / orig_w
.Height = max_h
.Width = max_h / r
End With
.Content.InsertAfter ("Additional text to follow")
end with
My question is: Through Excel, how can I insert an entire paragraph of text, then insert a small picture, aligned right, with the text from the paragraph wrapped around it?
After getting the word object and setting up a new Word document "word_doc"....right now I've got:
'// using word and excel 2007
With word_doc
.Content.InsertParagraphAfter
.Content.InsertAfter ("Sample text to start things off. This text should be long enough to take up several lines in a normal Word document. I don't know if I need to insert the picture before or after this text. At any rate this text should be on the left and a picture should be inserted on the right side of the word document with this text wrapped around it. I have no fixed location where this might be. It might be on the 2nd page of the Word document that i am creating and it might be on the 10th page.")
'// this is where I set the range as the last paragraph inserted.
'// again, this is where I don't know how to navigate around in Word through VBA
Set text_range = .Range(Start:=.Paragraphs(.Paragraphs.Count).Range.Start, End:=.Paragraphs(.Paragraphs.Count).Range.End)
text_range.ParagraphFormat.Alignment = wdAlignParagraphLeft
'// I have the picture link for the line below
Set word_image = text_range.InlineShapes.AddPicture("C:....", False, True)
max_h = 100
With word_image
orig_h = .Height
orig_w = .Width
r = orig_h / orig_w
.Height = max_h
.Width = max_h / r
End With
.Content.InsertAfter ("Additional text to follow")
end with