Word 97 - Bookmarks/table Cell Refs
Hi
I know how to create a simple bookmark in Word using VB, but is there a way to tell it to find a table cell ref and create the bookmark?
Thanks
Pendle
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Word 97: How To Insert A Table Into An Existing Table Cell
Does anyone know how I can insert a New Table into a cell of another table?
In Word 2000, I can issue the following code when I am within a cell of a table and the table gets inserted correctly:
Dim rRange As Range, myTable As Table
With Selection
Set rRange = .Range
Set myTable = rRange.Tables.Add(Range:=.Range, NumRows:=2, NumColumns:=4)
End With
However, in Word97, I am not able to do this. I get an error telling me that a table already exists. Has anyone had any success with being able to insert a new table into a cell of an existing table without doing a lot of cell/row inserts and cell merges?
How To Insert Table Into A Cell Of Another Table Using Word Object
hi friends,
i have inserted a table into word do using word object through VB
wddoc.tables.add selection.range, 2, 4
now i wanto to insert a table into the cell of the table created.
can u help me how to do that
i have tried like this
wddoc.tables(1).cell(1,1).range.tables.add selection.range,2,4
but i am getting an error saying that table already exists in that location,
PLEASE HELP ME OUT!!!!!
thanx
How To Insert Table Into A Table Cell Of Word
hi friends,
i am creating a word doc from VB and then i want to insert tables into it. i am inserting table in the following manner
wdapp.ActiveDocument.Tables.Add selection.range, 4, 1
wdapp.ActiveDocument.Tables.Add selection.range, 2, 2
but it is able to create the first table but not the second table. it is giving a error message saying that table already present in the location.
can u tell me how to insert 2 or more tables into the word doc through coding
thanx,
How To Insert Table Into A Table Cell Of Word
hi friends
i want to add a table inside a table cell, i am using the following code to achieve this, but i am getting and error saying that the table is already located in the location. i think there is some problem with the range.
wdapp.ActiveDocument.Tables(2).Cell(2, 1).Range.Tables.Add wdapp.ActiveDocument.Tables(2).Cell(2, 1).Range, 2, 1
thanx,
How To Insert Table Into A Table Cell Of Word
hi friends
i want to add a table inside a table cell, i am using the following code to achieve this, but i am getting and error saying that the table is already located in the location. i think there is some problem with the range.
set drange=wdapp.ActiveDocument.Tables(2).Cell(2, 1).Range
wdapp.ActiveDocument.Tables(2).Cell(2, 1).Range.Tables.Add drange, 2, 1
i am using word 8.0 dll i.e word 97
thanx,
------------------------------------------------
Good Friend...
------------------------------------------------
How To Get The Aligment Of A Table Cell In Word
Hi,
I have written a macro, which traverses the table of a word document and outputs the text in particular format to a text file. While doing so i need to retain the look of the table and for which i need to know the aligment of the cells in the table whether centered, left or right aligned.
Is there any means by which this be achieved?
Thanks
Niranjan
Getting Cell Alignment Of A Table In Word
Hi,
I have written a macro, which traverses the table of a word document and outputs the text in particular format to a text file. While doing so i need to retain the look of the table and for which i need to know the aligment of the cells in the table whether centered, left or right aligned.
Is there any means by which this be achieved?
Thanks
Niranjan
Copy A Cell To A Word Table
This type of topic has been going around a lot lately. I have been searching the forum, but am still lost on the subject. I have taught myself VBA in Excel and feel very comfortable with that. However, I know need to copy a cell(s) to a word table and am having a great deal of trouble with this. Can't seem to get it through my thick skull I guess. BTW have done a google search as well. Anyway, here is the story...
I have a sales worksheet that is filed out when an admin person answers the phone. The worksheet contains basic information...name address reason for call and the like. If the sale goes through I need the name and address copied into word for the contract (a lot double typing that can be typed once...push a button and presto; all of the fields in word are copied over). Anyway, if someone could spell this out for me, it would be a huge help. Thanks for the help in advance.
-JD
Selecting A Whole Cell In A Word Table
Hi there.
I'm struggeling with the following:
I have a Word document with 2 columns. It contains 100 rows, which gives a total of 200 cells.
One of the rows are looking something like this:
_______________________________
|________________|______________|
In my code, I'm able to locate/find the correct row I want to do my selection.
I have a bookmark (called "Labelx" where x is the number of the cell) in every cell.
I'm able to select the first cell (that is the cell to the left), and I'm also able to put my cursor in the next cell (the one to the right).
The big challenge is to "mark"/highlight/select the cell to the right.
The purpose is that I want to select this cell and delete all the contents in it.
Can anyone give me some direction?
So far I have this code:
BookM = "Label" & (i+2) 'This selects the bookmark in the row below the row I want to delete
ActiveDocument.Bookmarks(BookM).Range.Select
Selection.MoveUp Unit:wdLine, Count:=1
Selection.EndKey Unit:=wdStory, Extend:= wdExtend
Selection.Delete
This code, selects all the remaining rows in the documents and deletes them. This is my purpose.
But I also want the code to delete the cell to the right in the last row AFTER deleting the remaining rows.
Hope that my explaination is good enough, if not - give me a hint and I will try to improve.....
Colspan Of Table Cell In MS Word
Hi,
I'm wondering how my Macro can determine if a table cell in MS Word spans multiple columns and if so how many.
thanks in advance
MS WORD XP Table Cell Sizes
Hey there
I'm writing an application that reads data from a mutlidimensional array into tables in a word document. I've got it up and running with MS Word 2000, but with MS Word XP, some of the cell sizes on the tables are wrong.
anyone else run into something like this ?!?
oh btw. its not really VBA its in VB (using WORD10 library).
thanks in advance.
Word Creation - Table Cell Alignment
Hello everybody,
I am trying to create an MS word document automatically through VB. In that document, there should be a table. The table should have 4 columns. The data in the last two columns needs to be right aligned. I could create table and fill it with data from table. But I am not able to right align contents of 3rd and 4th columns of the table. Could anybody please help me ?
I am attaching the code I wrote(A part of it I got from net)
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oTable As Word.Table
Dim oTitle As Object
Dim iCount As Integer
Dim intYCount As Integer
Dim intXCount As Integer
Dim bCreateOrGot As Boolean
Dim intXMax As Integer
Dim intYMax As Integer
Dim strTitle As String
strTitle = "My word document"
Dim rstTable As ADODB.Recordset
Dim qryTable As String
qryTable = "SELECT artisteid,productionname, grossamount, (grossamount*17.5/100) as vat FROM artistevouchers"
Set rstTable = New ADODB.Recordset
rstTable.Open qryTable, cnnArtists, adOpenDynamic
intYMax = rstTable.Fields.Count
rstTable.MoveLast
intXMax = rstTable.RecordCount + 1
rstTable.MoveFirst
On Error Resume Next ' Defer error trapping.
bCreateOrGot = True
Set oWord = New Word.Application
bCreateOrGot = False
err.Clear ' Clear Err object in case error occurred.
If bCreateOrGot = False Then
With oWord
.Visible = True
.Documents.Add ("c:project
eceipt.doc")
End With
End If
Set oDoc = oWord.ActiveDocument
On Error GoTo 0
If bCreateOrGot = True Then
With oDoc.Application.Selection
.InsertBefore Text:=strTitle & vbCrLf
With .Find
.Text = "^l"
With .Replacement
.Text = ""
End With
.Execute Replace:=wdReplaceAll
End With
With .Font
.Bold = True
.Name = "Arial"
.Size = 8
End With
.MoveRight Unit:=wdCharacter, Count:=1
.InsertAfter Text:=vbCrLf
End With
Set oTable = oDoc.Tables.Add(Range:=Selection.Range, NUMROWS:=intXMax, NumColumns:=intYMax)
Else
With oDoc.Application.Selection
.InsertBefore Text:=vbCrLf & strTitle
Dim iloop As Integer
With .Find
.Text = "^l"
With .Replacement
.Text = ""
End With
.Execute Replace:=wdReplaceAll
End With
With .Font
.Bold = True
.Name = "Arial"
.Size = 8
End With
.MoveRight Unit:=wdCharacter, Count:=1
End With
Set oTable = oDoc.Tables.Add(Range:=oDoc.Range(Start:=17, End:=17), NUMROWS:=intXMax + 1, NumColumns:=intYMax)
End If
For intYCount = 0 To intYMax - 1 'Add headings
With oTable.Cell(Row:=1, Column:=intYCount + 1).Range
.InsertAfter Text:=rstTable.Fields(intYCount).Name
End With
Next
intXCount = 2
Dim f_total_gross_amount As Currency
Dim f_total_vat As Currency
f_total_gross_amount = 0
f_total_vat = 0
Do Until rstTable.EOF
oTable.Rows.Add
For intYCount = 0 To intYMax - 1
With oTable.Cell(Row:=intXCount, Column:=intYCount + 1).Range
If Not IsNull(rstTable.Fields(intYCount).Value) Then
Dim str_value As String
If (intYCount = 2) Then
f_total_gross_amount = f_total_gross_amount + rstTable.Fields(intYCount).Value
End If
If (intYCount = 3) Then
f_total_vat = f_total_vat + rstTable.Fields(intYCount).Value
End If
If (intYCount = 2 Or intYCount = 3) Then
str_value = String(12 - Len(CStr(rstTable.Fields(intYCount).Value)), Chr(32)) & Format(CStr(rstTable.Fields(intYCount).Value), "#0.00")
Else
str_value = CStr(rstTable.Fields(intYCount).Value)
End If
.InsertAfter Text:=str_value
Else
.InsertAfter Text:=""
End If
End With
Next intYCount
intXCount = intXCount + 1
rstTable.MoveNext
Loop
oTable.Rows.Add
With oTable.Cell(Row:=intXCount, Column:=2).Range
.InsertAfter Text:="Total"
End With
With oTable.Cell(Row:=intXCount, Column:=3).Range
.InsertAfter Text:=Format(CStr(f_total_gross_amount), "##########0.00")
End With
With oTable.Cell(Row:=intXCount, Column:=4).Range
.InsertAfter Text:=Format(CStr(f_total_vat), "##########0.00")
End With
oTable.AutoFormat Format:=wdTableFormatGrid8, ApplyBorders:=True, ApplyFont:=True, ApplyColor:=True, ApplyHeadingRows:=True
oTable.Select
With oDoc.Application.Selection
.Collapse Direction:=wdCollapseStart
.InsertParagraph
.Collapse Direction:=wdCollapseStart
End With
Set oTable = Nothing
Set oDoc = Nothing
Set oWord = Nothing
Create Textbox In Every Cell From A Word Table
Hallo everyone,
I have a table wich contains texts and images in every cell, I would like to select everything is in a cell and put it in a textBox,so I will have a textbox for every cell.
I try this
Count = 1
For currRow = 1 To (Selection.Tables(1).rows.Count)
For currCol = 1 To Selection.Tables(1).Columns.Count
Selection.GoTo What:=wdGoToBookmark, Name:="Bookmark_" & Count
Selection.Tables(1).Cell(currRow, currCol).Select
Selection.CreateTextbox
Selection.ShapeRange.Line.DashStyle = msoLineDash
Count = Count + 1
Next currCol
Next currRow
But I have an error anyone could help me?
Thany you.
Adelin
Selecting Text In A Word Table Cell
This has probably been answered many times before but I can't find the solution. I need to insert some text into a Word table and then change the font without affecting the text that was already in the cell. My code will look something like this:
Code:
Set oWord = CreateObject("Word.Application")
' Create a new Word document based on works_oder.dot template
oWord.application.Documents.Add App.Path & " emplatesworks_order.dot"
oWord.Visible = True
oWord.Activate
With oWord.ActiveDocument.tables(1) ' First table in Word template
.cell(1, 2).range.insertafter "Temp 0001"
.cell(2, 1).range.insertafter " " & cmbCustomers
.cell(2, 2).range.insertafter vbCrLf & txtDrawingNo
.cell(2, 4).range.insertafter vbCrLf & txtWorksOrderNo
.cell(3, 1).range.insertafter " " & txtCustOrderNo
.cell(4, 1).range.insertafter vbCrLf & txtRequiredBy
.cell(4, 2).range.insertafter vbCrLf & txtDescription
End With
I guess I need to select the text I've just added and then apply the font formatting I need, but I can't quite work out the syntax to select just the new text and exclude the original contents of the cell. Thanks!
How To Retrive An Image From A Table Cell Of Word Doc
hi friends,
i have inserted an image using the following code-
wdapp.ActiveDocument.Range.InlineShapes.AddPicture("c:image1.gif")
how should i retrieve this image into a picture box without losing the quality of the image,
i have tried with the
range.copy
picture1.picture=clipboard.getdata
i got the image but the image quality is very poor!!
HELP ME OUT PLEAAZZZZZZ..
THANX.
How To Retrive An Image From A Table Cell Of Word Doc
hi friends,
i have inserted an image using the following code-
wdapp.ActiveDocument.Range.InlineShapes.AddPicture("c:image1.gif")
how should i retrieve this image into a picture box without losing the quality of the image,
i have tried with the
range.copy
picture1.picture=clipboard.getdata
i got the image but the image quality is very poor!!
HELP ME OUT PLEAAZZZZZZ..
THANX.
Word Table: Mixed Cell Widths ?
Please, help in this situation.
My Word-table has some splitted cells in a header.
I try to insert data to lower cells. But I have the message "Cannot access individual columns in this collection because the table has mixed cell widths. How to work with a table of such kind?
Thanks.
MSWORD Making One Word Bold In A Table Cell.
Hi
I am creating a report in word using tables in VB6.
One of the cells contains a surname and then two foren
ames for married
partners. I need to have the surname in bold and the
forenames as
normal.
When I do this I can make the whole cell bold or n
ormal. Can anybody
help?
Regards
Peter
Important Note: This E-Mail is confidential, it must not
be read,
copied, disclosed or used by any person other than the
above
named addressees. Unauthorised use, disclosure or copying is
strictly prohibited and may be unlawful. Eurostar (U.K.) L
imited
and Eurostar Group Limited disclaim any liability for any
action
taken in reliance on the content of this E-Mail. The c
omments
or statements expressed in this E-Mail are not necessarily
those
of Eurostar (U.K.) Limited, Eurostar Group Limited or any
subsidiaries or affiliates of either company.
Eurostar (U.K.) Ltd. Registered Office: Eurostar House, Wate
rloo
Station, London, SE1 8SE, Registered in England No. 246200
1
VAT No. GB 657 719 590
Eurostar Group Ltd. Registered office: Eurostar House, Water
loo
Station, London, SE1 8SE, Registered in England No. 379464
2
VAT No. GB 739 974 173
This email has been scanned for all viruses by the Mes
sageLabs Email
Security System on behalf of Eurostar. For more informatio
n on a proactive email security service working around t
he clock, around the globe, visit http://www.messagelabs.com
Change Font Bold Of A Cell In A Table In Word From VB
I've used some code from johnwm in thread222-589129 some time ago to help me make the table. From that I've figured out how to change the "header row" background color. Now I'm trying to change the "header row" font to bold but I'm having diffieculty. Can someone help. Here is the how I change the color of row 1 for each column.
CODE'This will change the color of the header row in the table
With MyRange.Tables.ITEM(1)
For g = 1 To .Columns.Count
' .Cell(1, g).Select.Font.Bold = wdToggle
.Cell(1, g).Shading.BackgroundPatternColor = wdColorYellow
Next g
End With
Problem Accessing A Merged Cell In A Word Table Using MACRO
Hi ,
I am writing a macro which converts a MS WORD table into particular format. I need to retain the structure of the table while doing so.
The main problem is that if a row consists of a merged cell then there is no means to identify this at runtime. If a merged cell has occured in the input table i need to place a identifier for the same in the output....
Could anyone please let me know how can i achive this ?
Thanks
Changing Text Orientation/Direction In Table Cell - VBA Word Automation
Hi,
I need to change the text direction/orientation to 90 degrees in a table cell in a Word document using automation. I know how to achieve this manually.
Right click on a table cell, select Text direction, in the window: select the orientation you want.
The same result I need to achieve through VBA automation. I am using Word 2003 & VB 6.
Could you please help me out in this regard ?
Thanks in advance.
Sisheer
Between Two Bookmarks (VB/WORD)
Hi
It's possible to get all the text (and images if can be possible) in a Word File between two bookmarks:
Something like this:
Quote:
-Start: BookMark1-
All the text that are store in a Word File
-another bookmar-
more text and a image
-ENDBookMark1-
That I want is to extract all that values in the Word file between StartBookmark1 and EndBookMark1 and place it into another word document
Is this possible? Thanks in advance
P.S: The bookmarks are empty, I only use them to locate the cursor, and know where starts and where end
Word And Bookmarks
Hi
I'm trying to place results from formulas in Excel into Word but having trouble with the positioning.
I've heard that bookmarks and the way to go but cant work out the code through VBA to place onto a word doc
Any ideas?
Thanks in advance
Bookmarks In Word
Hi All,
I have several word documents which have several bookmarks in them. My problem is that i need to change the name of a bookmark from "Payment" to "Paid" in all these files. The corresponding changes have to be done in the Hyperlinked text which referes to this bookmark in all the attachments.
Please can someone help me write the macro that can do this or even guide me to the correct place.
Thanks,
Lonely
Word, Bookmarks, And VB
Hi Everyone,
My problem is that I have word template with bookmarks and some of the bookmarks appear several times throughout the template. I want to use a vb form using text boxes and radio buttons to interface with the word template and fill in the bookmarks. I can't seem to get the multiple bookmarks to work. Does anyone have any suggestions? Thanks
Bookmarks In Word
Hello,
I read almost all threads about this subject but I didn't found an answer to my problem. What I want to do:
I select a few records from an Access database and I want to print these records in a table in Word. I created a table and in each column I put a bookmark. So far so good, but the amount of records can be variable. So I can select 1 til 1000 records. I don't want to make 1000 rows with bookmarks in it... it is a lot of work and if I don't use them I see the rows.
Can someone help me with this problem.
Regards, Silvano.
Bookmarks In Word
I am creating documents in Word in my app and populating the documents with data via bookmarks. This works fine - the problem I have is that in order to put data on the doc I ask the user questions and fill the doc up depending on the answers. I don't want the doc to appear until it is complete. But if the user has Word open already with another document, this one appears in an uncompleted state - how can I stop it showing? It is fine unless there is already a document active on the PC.
Bookmarks In Word
I am busy with a macro to put data from a textfile into a Word document using bookmarks. Here is the code:
Code:
Dim a(16) As String, x As Integer
Open "c:VBA ester.txt" For Input As #1
While Not EOF(1)
x = x + 1
Line Input #1, a(x)
ActiveDocument.Bookmarks(x).Select
Selection.InsertAfter Text:=a(x)
Wend
Close #1
I have named my bookmarks a1 to a16. The macro places the first string into a1, no problem. The next one, though, it places in a10, continues through to a16, then only goes to a2, a3, etc.
Is there any way to change the order of the bookmarks to make my macro work correctly?
Bookmarks In Word
I am having trouble getting my vb code to fill Word bookmarks. This is my code:
Dim objWord As Word.Application
Set objWord = New Word.Application
objWord.Visible = True
'Open Template
objWord.Documents.Add Template:="P:Submittal DataDataTemplate.dot", NewTemplate:=False
'Put in text
objWord.Selection.Goto What:=wdGoToBookmark, Name:="Equip"
objWord.Selection.TypeText strEquip
I keep getting object variable or with block variable not set error
Also, how do I print the document when I'm finished?
From VB To Word Doc's Bookmarks
Dim vals() As String
Dim wrd As Word.Application
Dim doc As Word.Document
Dim x As Integer
Set wrd = New Word.Application
Set doc = wrd.Documents.Open("C:Path_to_file.doc")
ReDim vals(doc.FormFields.Count - 1)
For x = 1 To doc.FormFields.Count
vals(x - 1) = doc.FormFields(x).Result
Next
wrd.Quit
==========================================
Previously [LGS]Static wrote (above) the code to extract Word doc's bookmarks works perfectly. Now I want to reverse it (from VB to word doc) and hit error on statement below:
For X = 1 to doc.FormFields.Count
doc.FormField(X-1).result = txtBKValue(X-1).Text
-> Run Time Error '4120', Bad Parameter
Next
Why?
I also used the statement(s) you suggested and work. But I have 42 fields and I need toplace 42 similar statements below.
wrd.FormFields("Text7").Result = txtBKValue(1).Text
Any good way to solve it ?
Thanks.
vb999
Vb Word Bookmarks..not Going There
I have the following:
VB Code:
Private Sub mnuAutoCadDwgReq_Click()On Error GoTo AdoErrorDim objWord As Word.ApplicationDim objDoc As Word.DocumentDim objDB As Word.Range Set objWord = CreateObject("Word.Application")Set objDoc = objWord.Documents.Open("\ANDREWSJAK_Eng_Data 000 JAK Mechanical StandardsStandards ManualChapter 1.doc")objWord.Visible = True objWord.ActiveDocument.GoTo wdGoToBookmark, , , "BM_1_5_1" With objDoc.Bookmarks .DefaultSorting = wdSortByName .ShowHidden = FalseEnd With Done:Exit Sub AdoError: MsgBox Err.Description, vbCritical, "Error #: " & Err.Number Resume Done End Sub
From a vb application. I open the document, which is fine..but I specify a bookmark to go directly to and it never does..it just opens up at the top of the document. Can anyone point out my mistake or give me a hand.
Thanks,
Jon
Bookmarks In Word
Hi, I have a document that utilises bookmarks.
I use the bookmarks to insert text at certain places within the document.
My problem is that I want to update the bookmark text via code..
e.g
oWordDoc.Bookmarks.Item("PersonName").Range.InsertBefore("Personsname")
When I do this the text is appended to the text that already exists for the
bookmark.
What I would like to do is clear the existing text and insert some new text
in its place.
I tried calling the delete method but this deletes the bookmark as well.
Any help appreciated
Mark
Word Bookmarks
Hi,
Does anyone know how I can get vb to open up a word document so that a particular bookmark is displayed rather than opening up at the top of the document every time.
Thanks
Mark
Word Bookmarks
Hi
Using a VB-Script form I am trying to read from Word a string of text between two bookmarks. I use the following code to read the text in however I am unsure of the syntax to stop the loop once the second bookmark is reached.
Selection.GoTo what:=wdGoToBookmark, Name:="bookmark1"
character = selection.text
Thanks
Bookmarks In Word
I'm trying to access Bookmarks in Word and place text in the
document at that point. I can get VB6 to open Word and the template I'm using. However, I get an error message telling me I'm not using the syntax correctly.
Can anyone HELP me!!!! PLEASE!!!!
That's the only problem in this program.
Bookmarks In Word 6 Vs Word 2002
I'm converting some Word 6 code to Word 2002 and I'm a a it baffled how some stuff works differently. For example the bookmarks.
This WD6 code counts the bookmarks in the header only
Code:size_ = WordBasic.CountBookmarks() - 1
Whereas this code in WD2002 counts all the bookmarks in document.
Code:ActiveDocument.Bookmarks.Count
The only way I could duplicate the same count as the WD6 code was to do the following.
Code:
Public Function CountHeaderBookmarks() As Integer
Dim oBookmark As Bookmark
Dim oBookmarks As Bookmarks
Dim iCount As Integer
Set oBookmarks = ActiveDocument.Bookmarks
For Each oBookmark In oBookmarks
If oBookmark.StoryType = wdMainTextStory Then
iCount = iCount + 1
End If
Next oBookmark
CountHeaderBookmarks = iCount - 1
End Function
Is this correct or is there an easier way?
Or is it simply that its just different in VBA6.3?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/html/wrgrfbookmarkobject.asp
Edited by - Sparky191 on 12/16/2003 3:11:18 PM
Adding New Bookmarks Into Word Doc
Hi Guys 'n Galls,
I am trying to fill a Word form from VB. So far I have done this using Bookmarks I set in the Word-Doc. But now I would like to add some bookmarks from VB, so that I can be more flexible with the data I am adding.
My questions are:
How do I add a new bookmark to my Doc using VB code?
How can I define where I want this Bookmark to be?
Thanks in advance,
Chris
Question Regarding VBA Word Bookmarks
I have a Access program that has a DB tied to a form. Users just fill in the form the same as they would if it were on paper (minus the pens obviously ). The form fits perfectly on an 8.5x11 inch sheet.
I am adding the ability to export the data to MS Word. Each record / form is one page, and when I export them to word, I want them all in the same file - one page after another.
I open the word doc using a template with bookmarks B1-B50 which give me the fields, and I fill in the text. The Word form is basically contructed with lines and text boxes. The text boxes are where the bookmarks are.
Right now, I basically have a tempDoc and a totalDoc. TempDoc is opened with the template and the data is pumped in. I then copy it, and paste it to TotalDoc and fill in TempDoc again, and paste again until the records are all done.
The problem is this - how do I clear the text in the bookmarks from the last record on tempDoc. The way it is now, it just appends it. For example, if the data has "Hey" a field in the first record and "You" for the same field in the second record, my 2nd word page/form would contain "HeyYou" in that field/textbox.
To get around this, I closed TempDoc, then re-opened it to clear the data each loop, but I'm sure this causes un-needed processor cycles and slows down the application.
Here is the basic code - if you are still with me.
Basically,
How do I clear the data in tempDoc.Bookmarks(s).Range.Text ??
That line appears to just be appending the data onto what is already there... not replacing it - which is what I want.
I am also open to any other pointers about the code below? Am I going about this the wrong way? I'm no expert when it comes to VBA or VB for that matter, so if the code is screwed up, I'd like some fixes / opinions / easier way to do things / performance improvements / etc.
Code:
Public Sub WordExport()
Set m_objWord = New Word.Application
m_objWord.Visible = False
Dim i As Integer, s As String, strWorkingDocName As String
Dim tempDoc As Word.Document
Dim totalDoc As Word.Document
Dim totalRange As Range
Dim tempRange As Range
m_objWord.Documents.Add
strWorkingDocName = m_objWord.ActiveDocument.Name
Set totalDoc = m_objWord.Documents(strWorkingDocName)
Dim MyLocation As String
MyLocation = "C:mytemplate.dot"
Set tempDoc = m_objWord.Documents.Add(MyLocation)
Set totalRange = totalDoc.Range
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("Sorted", dbOpenDynaset)
rst.MoveFirst
Do While Not rst.EOF
'This is where I tested the idea of closing and re-opening each loop
'Set tempDoc = m_objWord.Documents.Add(MasterLoc)
For i = 0 To 50
'need this (I think) because you can't call a bookmark just a #
s = "B" & i
tempDoc.Bookmarks(s).Range.Text = rst.Fields(i)
Next i
rst.MoveNext
'copy from temp to total
Set tempRange = tempDoc.Range(Start:=tempDoc.Content.Start, End:=tempDoc.Content.End)
tempRange.Copy
totalRange.Paste
If (Not rst.EOF) Then
totalRange.Collapse Direction:=wdCollapseEnd
totalRange.InsertBreak Type:=wdPageBreak
End If
'This is where I used the idea of closing and re-opening each loop
'tempDoc.Close wdDoNotSaveChanges
Loop
rst.Close
Set rst = Nothing
tempDoc.Close wdDoNotSaveChanges
m_objWord.Visible = True
Set tempDoc = Nothing
Set totalDoc = Nothing
Set m_objWord = Nothing
Set totalRange = Nothing
Set tempRange = Nothing
End Sub
Listing Word Bookmarks In VB
I'm trying to write a little program that lists all of the bookmarks in a Word document - similar to the add-bookmark dialogue that comes with Word. All I want to do is add the name of each bookmark to a listbox. I have no troulbe getting the bookmark names into the listbox in alphabetical order. But I can't seem to get the bookmarks into the listbox in the order they exist in the document. No matter what I do, it comes in alphabetically, regardless of how I have the sorted property set. This is the code I'm using:
For Each booky In Word.ActiveDocument.Bookmarks
lst.AddItem booky.name
Next
I'm sorry if this is a very newbie-ish question. Any help would be greatly appreciated!
Mick
Arranging Bookmarks In Word
Hi
I am trying to add bookmarks to a Word doc that I create. I want these bookmarks to be underneath eachother. I have the following code. (The result of this code is that the bookmarks seem to be placed on top of eachother)
Set WordObject = CreateObject("Word.Application")
With WordObject
.Documents.Open (App.Path & "Test.dot")
.ActiveDocument.Bookmarks("StudName").Select
.Selection.Text = CurrentStudent
'.ActiveDocument.Bookmarks.Add
.ActiveDocument.Bookmarks("StudData").Select
m_rs.MoveFirst
Do While Not m_rs.EOF
.Selection.Text = m_rs("ExamDate").Value & Chr(9) & Chr(9) & m_rs("Exam").Value & Chr(9) & Chr(9) & m_rs("Mark").Value & Chr(9) & Chr(9) & m_rs("Result").Value & vbCrLf
.ActiveDocument.Bookmarks.Add ("c" & lHolder)
.ActiveDocument.Bookmarks("c" & lHolder).Select
lHolder = lHolder + 1
m_rs.MoveNext
Loop
End With
WordObject.Visible = True
'quite word
If Not (WordObject Is Nothing) Then Set WordObject = Nothing
Thanking you in advance
SL55
Bookmarks In Userform Word
On a user form I want this to occur. When the an option in the Drop-down Form Field is selected, the text in Bookmark”Student” and text “well done” will be copied to Bookmark”Comment”
My code does not work and no errors occur. Any ideas please.
Sub BookmarkCopy()
Dim bmComment As String
Dim bmStudent As String
bmComment = ActiveDocument.Bookmarks("BehaveComment").Range.Text
bmStudent = ActiveDocument.Bookmarks("Student").Range.Text
With ActiveDocument
If .Bookmarks("BehaveRating").Range.Text = "A" Then
bmComment = bmStudent & "Well done"
End If
End With
End Sub
Extract Bookmarks Value From Word.doc
Anybody please help me out how to extract bookmarks values from a word doc?
I have a word document with many bookmarks field named from Text1, Text2, Text3....etc.
What I did was:
Dim w As Word.Document
Dim a As Word.Application
Dim output1 As String
Set a = New Word.Application
Set w = New Word.Document
Set w = a.Documents.Open("c:my document est303.doc")
output1 = w.Bookmarks.Item(1) -> This only retreive BookMarks name as "Text1" The "Text1" current contains value "ABC Company". How to extract value from "Text1"?
Thanks.
Retrieve Bookmarks Value In Word Doc.
Quesiton: how to retreive Bookmarks value from word doc
I have a word document with many bookmarks field named from Text1, Text2, Text3....etc.
What I did was:
Dim w As Word.Document
Dim a As Word.Application
Dim output1 As String
Set a = New Word.Application
Set w = New Word.Document
Set w = a.Documents.Open("c:my document est303.doc")
output1 = w.Bookmarks.Item(1) -> This only retreive BookMarks name as "Text1"
How do I get the value from "Text1"? The Text1 contains value "ABC Company".
Appreciate anyone's help. Thank you.
14
Writting To Word Bookmarks
I have made a Word Template with Bookmarks and an application that writes to the bookmarks with data from the app. I have Word 2003 installed on my system. After creating the setup and installing it on another system the App crashed, I then noticed the other system has XP installed. So here is my question, is there a way to create an app that write data to bookmarks within Word that is independant of the version of Word being using? I will need to it work on systems with Word 2000, XP or 2003 installed.
I tried some test code, trying to make it work but was not successful, only works with the version of Word installed on my system. Here is the test code I used...
Dim WordApp As New Word.Application
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ReportGenerator As New Word.Document
ReportGenerator = WordApp.Documents.Open("C:Report GeneratorDemo.doc")
With ReportGenerator
If Len(txtName1.Text) > 0 Then
.Bookmarks("Name1").Select()
WordApp.Selection.TypeText(txtName1.Text)
End If
If Len(txtName2.Text) > 0 Then
.Bookmarks("Name2").Select()
WordApp.Selection.TypeText(txtName2.Text)
End If
.Close(Word.WdSaveOptions.wdSaveChanges)
End With
WordApp.Quit()
Thanks
Arranging Bookmarks In Word
Hi
I am trying to add bookmarks to a Word doc that I create. I want these bookmarks to be underneath eachother. I have the following code. (The result of this code is that the bookmarks seem to be placed on top of eachother)
Set WordObject = CreateObject("Word.Application")
With WordObject
.Documents.Open (App.Path & "Test.dot")
.ActiveDocument.Bookmarks("StudName").Select
.Selection.Text = CurrentStudent
'.ActiveDocument.Bookmarks.Add
.ActiveDocument.Bookmarks("StudData").Select
m_rs.MoveFirst
Do While Not m_rs.EOF
.Selection.Text = m_rs("ExamDate").Value & Chr(9) & Chr(9) & m_rs("Exam").Value & Chr(9) & Chr(9) & m_rs("Mark").Value & Chr(9) & Chr(9) & m_rs("Result").Value & vbCrLf
.ActiveDocument.Bookmarks.Add ("c" & lHolder)
.ActiveDocument.Bookmarks("c" & lHolder).Select
lHolder = lHolder + 1
m_rs.MoveNext
Loop
End With
WordObject.Visible = True
'quite word
If Not (WordObject Is Nothing) Then Set WordObject = Nothing
Thanking you in advance
PORRASTAR
MS Word Form Bookmarks
I'm sure this is quite trivial:
I have a combobox in a form as a bookmark. I choose from a list of people in the combobox (no problem), but I want a phone number to appear elsewhere on the page after I selected one person. I am not familiar with handling bookmarks in VB. I can do the If..then..else statements, but I don't know how to control the bookmark combobox in VB.
Can anyone help?
Bookmarks Word And Pictures
Hi,
I was hoping someone could help i have a simple template and a user form which inserts text from Textboxs at the bookmarks.
HOw can i also insert a picture at the bookmark? Is this the right/wrong approach please help
Thanks
Bookmarks And Word Documents
I read the recent bookmark help that was provided and thought it was well done. I do have a question I haven't seen a solution to yet.
I have a bookmark in a document and I would like to add four bookmarks on individual lines below the original bookmark programmatically.
for example:
[exisiting bookmark]
-new bookmark through code
-new bookmark through code
-new bookmark through code
-new bookmark through code
I have seen a lot of use of (range) RNG but it appear to be more pixel related or x,y rather than a actual new line.
Is it possible to add a bookmark to a specific line in a word document?
VBA - Word Bookmarks Alternative
I am currently working on a VB application that uses bookmarks on a word template
to insert fields from a database.
I have been instructed to use an alternative method that is supposed to be
called DataField. The advantage is apparently that you can use DataFields
to set the same reference in multiple places in a word document. Bookmarks
requires a seperate reference on each occaision even if the contents of the
field are the same.
For example if typing a letter and you insert the recipient "Mr J. Smith"
in a number of locations on the letter with bookmarks you have to set up
a distinct reference each time.
Does anyone know anything about using DataFields or perhaps it's called something
else. But apparently it exists and is superior to using bookmarks.
Any help would be greatly appreciated.
Jeff
|