Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert image into Word 3

Status
Not open for further replies.

Enkrypted

Technical User
Joined
Sep 18, 2002
Messages
663
Location
US
We have an web application that we use that gathers information from our database to print a follow up letter to customers. I am having some trouble getting it to put an image into a word document though.

Code:
Function wrdFollowupLetter(custname, custa1, custa2, custnamesal, repname, repphone)
	'response.write "Custname: " & Custname & " / CustA1: " & custa1 & " / CustA2: " & custa2 & " / CustSal: " & custnamesal & " / Repname: " & repname & " / Repphone: " & repphone & "<br>"
	'RESPONSE.FLUSH
	Const wdSaveFormat = 1
	Set oWord = CreateObject("Word.Application")
	oWord.DisplayAlerts = false
	oWord.Visible = False
	Set oDoc = oWord.Documents.Add("c:\Inetpub\Sharp_Intranet\WordDocuments\followupletter.dot")
	[b][COLOR=red]Set reppic = "C:\Inetpub\test.jpg"[/color][/b]
	oWord.Options.PrintBackground = True
	oDoc.Bookmarks("CustName").Range.Text = custname
	oDoc.Bookmarks("CustA1").Range.Text = custa1
	oDoc.Bookmarks("CustA2").Range.Text = custa2
	oDoc.Bookmarks("CustNameSal").Range.Text = custnamesal
	oDoc.Bookmarks("CustRep").Range.Text = repname
	oDoc.Bookmarks("RepPhone").Range.Text = repphone
	oDoc.Bookmarks("RepPhone2").Range.Text = repphone
	[b][COLOR=red]oDoc.Bookmarks.Item("reppic").Range.InlineShapes.AddPicture = reppic[/color][/b]
	oDoc.PrintOut
	'oDoc.SaveAs "c:\test3.doc", wdSaveFormat
	oDoc.Close 0
	oWord.Quit
	Set oDoc = nothing
	Set oWord = nothing
End Function

The code that is in bold and red is what I have been playing around with. As you can see from the following, we have a link that when clicked, it will pull our Rep's name and phone number, as well as the customer name/address, etc. We would like it to also pull a pic depending on what rep it is. I am just not sure how to code that properly. Any help is appreciated. TIA!

Enkrypted
A+
 
>Set reppic = "C:\Inetpub\test.jpg"
No chance of it being correct.
[tt]reppic = "C:\Inetpub\test.jpg"[/tt]
 
Thank you Tsuji!

Enkrypted
A+
 
One final question I have:

reppic = "C:\Inetpub\test.jpg"

For our follow up letter to pull the rep's pic depending on the customer I have the following:

reppic = '"C:\Inetpub\' & repname & '.jpg"'

The repname pulls the information from our database of first and last name (i.e.- My Name). With that space being there, is there a certain naming convention that has to be used? I was sure the quotes would have handled that.

Enkrypted
A+
 
Making/escaping quote to a string is by double it up. Also apostrophe is not the symbol to delimit a literal string for vbs.
[tt] reppic = """C:\Inetpub\" & repname & ".jpg"""[/tt]
 
I changed it to the following as noted, but it doesn't appear to be doing anything. When I click on the link, I can hear a beep emit from the computer and the page acts like it is trying to print, but it doesn't.

Enkrypted
A+
 
AddPicture is a method.
[tt] oDoc.Bookmarks.Item("reppic").Range.InlineShapes.AddPicture[highlight] [/highlight]reppic[/tt]
(There are further parameters to set if needed. Check documentation.)
 
I've just made a quick testing page. The file with space in it would be gracefully accepted. Hence not need to quote it, at all. This would be fine.
[tt] reppic = [highlight]"[/highlight]C:\Inetpub\" & repname & ".jpg[highlight]"[/highlight]
oDoc.Bookmarks.Item("reppic").Range.InlineShapes.AddPicture[highlight] [/highlight]reppic[/tt]
 
Thanks again Tsuji!!!

Enkrypted
A+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top