HOW to insert data values in word document
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
HOW to insert data values in word document
How to insert in this doc the value from Access recordset ?
No idea!
No idea!
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78416
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: HOW to insert data values in word document
First, open the document in Word.
Insert a bookmark in each location of the document where you want to place a value from your recordset.
Give each bookmark a clear and meaningful name, for example Destinatario and DataFattura.
Save the document.
In your VB6 project, use Automation to start Word, open the document, set the values of the bookmarks, then save the document under another name. Quit Word when you have processed all records.
Insert a bookmark in each location of the document where you want to place a value from your recordset.
Give each bookmark a clear and meaningful name, for example Destinatario and DataFattura.
Save the document.
In your VB6 project, use Automation to start Word, open the document, set the values of the bookmarks, then save the document under another name. Quit Word when you have processed all records.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
Re: HOW to insert data values in word document
FIRST TET, dont work!HansV wrote: ↑24 Apr 2022, 08:28First, open the document in Word.
Insert a bookmark in each location of the document where you want to place a value from your recordset.
Give each bookmark a clear and meaningful name, for example Destinatario and DataFattura.
Save the document.
In your VB6 project, use Automation to start Word, open the document, set the values of the bookmarks, then save the document under another name. Quit Word when you have processed all records.
Code: Select all
Private Sub FATTURA()
Dim APP As Object
Dim DOC As Object
Set APP = CreateObject("WORD.Application")
APP.Visible = True
Set DOC = APP.documents.Open("C:\Lavori_Vb6\HOTEL\Fattura.doc")
DOC.Bookmarks("IMMAGINE").Select
DOC.Selection.InlineShapes.AddPicture FileName:="C:\Lavori_Vb6\HOTEL\IMG\RISTORANTE.bmp", LinkToFile:=False, SaveWithDocument:=False
DOC.booksmarks("NOME_AZIENDA").Range.Text = "TEST"
DOC.printout
DOC.Close
Set DOC = Nothing
APP.quit
Set APP = Nothing
End Sub
-
- Administrator
- Posts: 78416
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: HOW to insert data values in word document
Where does it fail? And what is the error message?
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
Re: HOW to insert data values in word document
Error In:
DOC.Selection.InlineShapes.AddPicture FileName:="C:\Lavori_Vb6\HOTEL\IMG\RISTORANTE.bmp", LinkToFile:=False, SaveWithDocument:=False
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78416
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: HOW to insert data values in word document
Change DOC.Selection to APP.Selection
Best wishes,
Hans
Hans
-
- Administrator
- Posts: 78416
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: HOW to insert data values in word document
Or change
to
Code: Select all
DOC.Bookmarks("IMMAGINE").Select
DOC.Selection.InlineShapes.AddPicture FileName:="C:\Lavori_Vb6\HOTEL\IMG\RISTORANTE.bmp", LinkToFile:=False, SaveWithDocument:=False
Code: Select all
DOC.InlineShapes.AddPicture FileName:="C:\Lavori_Vb6\HOTEL\IMG\RISTORANTE.bmp", LinkToFile:=False, SaveWithDocument:=False, Range:=DOC.Bookmarks("IMMAGINE").Range
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
Re: HOW to insert data values in word document
i test this after..HansV wrote: ↑25 Apr 2022, 07:25Or change
toCode: Select all
DOC.Bookmarks("IMMAGINE").Select DOC.Selection.InlineShapes.AddPicture FileName:="C:\Lavori_Vb6\HOTEL\IMG\RISTORANTE.bmp", LinkToFile:=False, SaveWithDocument:=False
Code: Select all
DOC.InlineShapes.AddPicture FileName:="C:\Lavori_Vb6\HOTEL\IMG\RISTORANTE.bmp", LinkToFile:=False, SaveWithDocument:=False, Range:=DOC.Bookmarks("IMMAGINE").Range
but see the code write TEST! instead in the bookmark NOME_AZIENDA!!!!
the code:
....
Dim APP As Object
Dim DOC As Object
Set APP = CreateObject("WORD.Application")
Set DOC = APP.documents.Open("C:\Lavori_Vb6\HOTEL\Fattura.doc")
With DOC.Bookmarks
.Item("NOME_AZIENDA").Range.Text = "TEST"
'.Item("ADDRESS").Range.Text = ADDRESS
'.Item("POSTCODE").Range.Text = POSTCODE
'.Item("DESCRIPTION").Range.Text = Description
'.Item("COST").Range.Text = COST
'.Item("GROSS").Range.Text = GROSS
'.Item("VAT").Range.Text = VAT
'.Item("DEPOSIT").Range.Text = DEPOSIT
'.Item("NET").Range.Text = NET
End With
.....
peraphs i need to select the bookmark before .Item("NOME_AZIENDA").Range.Text = "TEST"?
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78416
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: HOW to insert data values in word document
Are you sure that you created bookmarks? They look like hyperlinks to me...
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
-
- Administrator
- Posts: 78416
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: HOW to insert data values in word document
Here you go.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
Re: HOW to insert data values in word document
HansV wrote: ↑25 Apr 2022, 07:25Or change
toCode: Select all
DOC.Bookmarks("IMMAGINE").Select DOC.Selection.InlineShapes.AddPicture FileName:="C:\Lavori_Vb6\HOTEL\IMG\RISTORANTE.bmp", LinkToFile:=False, SaveWithDocument:=False
HERE error 4120 parametro erratoCode: Select all
DOC.InlineShapes.AddPicture FileName:="C:\Lavori_Vb6\HOTEL\IMG\RISTORANTE.bmp", LinkToFile:=False, SaveWithDocument:=False, Range:=DOC.Bookmarks("IMMAGINE").Range
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
Re: HOW to insert data values in word document
In this case peraphas...sal21 wrote: ↑25 Apr 2022, 20:34HansV wrote: ↑25 Apr 2022, 07:25Or change
toCode: Select all
DOC.Bookmarks("IMMAGINE").Select DOC.Selection.InlineShapes.AddPicture FileName:="C:\Lavori_Vb6\HOTEL\IMG\RISTORANTE.bmp", LinkToFile:=False, SaveWithDocument:=False
HERE error 4120 parametro erratoCode: Select all
DOC.InlineShapes.AddPicture FileName:="C:\Lavori_Vb6\HOTEL\IMG\RISTORANTE.bmp", LinkToFile:=False, SaveWithDocument:=False, Range:=DOC.Bookmarks("IMMAGINE").Range
Other way are welcome to insert a Little image.
-
- Administrator
- Posts: 78416
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: HOW to insert data values in word document
I should have seen that. If LinkToFile is False, SaveWithDocument should be True:
Code: Select all
DOC.InlineShapes.AddPicture FileName:="C:\Lavori_Vb6\HOTEL\IMG\RISTORANTE.bmp", LinkToFile:=False, SaveWithDocument:=True, Range:=DOC.Bookmarks("IMMAGINE").Range
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
Re: HOW to insert data values in word document
super!HansV wrote: ↑25 Apr 2022, 20:44I should have seen that. If LinkToFile is False, SaveWithDocument should be True:
Code: Select all
DOC.InlineShapes.AddPicture FileName:="C:\Lavori_Vb6\HOTEL\IMG\RISTORANTE.bmp", LinkToFile:=False, SaveWithDocument:=True, Range:=DOC.Bookmarks("IMMAGINE").Range
Work now!
Tks bro.
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
Re: HOW to insert data values in word document
OK.ALL TESTED.HansV wrote: ↑25 Apr 2022, 20:44I should have seen that. If LinkToFile is False, SaveWithDocument should be True:
Code: Select all
DOC.InlineShapes.AddPicture FileName:="C:\Lavori_Vb6\HOTEL\IMG\RISTORANTE.bmp", LinkToFile:=False, SaveWithDocument:=True, Range:=DOC.Bookmarks("IMMAGINE").Range
Now, how to save as pdf file the doc filled with new value, and close the doc without save it.
Note:
save as the pdf in c:\mydir\ with a name based the string var named VALORE
-
- Administrator
- Posts: 78416
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: HOW to insert data values in word document
Use
Code: Select all
DOC.ExportAsFixedFormat OutputFileName:="c:\mydir\" & VALORE & ".pdf", ExportFormat:=17
DOC.Close SaveChanges:=False
Best wishes,
Hans
Hans