hi,
i'm using the following code to modify a standard word document and save it to disk with a new file name. - Sub CreateQuote()
-
'***************************************************************************
-
'Quotation part
-
'***************************************************************************
-
Dim appWord As New Word.Application
-
-
Dim intRMA, i As Integer
-
Dim strDate, strFileName As String
-
Dim Range As Range
-
-
'Define the path where to save the RMA.doc
-
intRMA = InputBox("RMA Number:", "Create Quotation Document", "")
-
strDate = Format(Now(), "yyyy-mm-dd")
-
strFileName = "CAR " & intRMA & " Spare Part Quote.doc"
-
-
'Open the RMA Word Template
-
appWord.Documents.Open ("C:\Documents and Settings\qtomlyc\My Documents\Attachments\NEW Spare Part Quote.doc")
-
-
' Make Word invisible through the Application object.
-
appWord.Visible = False
-
-
'Change date in document
-
For i = 1 To 15
-
Set Range = appWord.ActiveDocument.Content
-
Range.Find.Execute FindText:="2007-XX-XX", ReplaceWith:=strDate
-
Next i
-
-
'Change reference of RMA in document
-
For i = 1 To 15
-
Set Range = appWord.ActiveDocument.Content
-
Range.Find.Execute FindText:="XXXX", ReplaceWith:=intRMA
-
Next i
-
-
' Save the new RMA document
-
appWord.ActiveDocument.SaveAs "C:\Documents and Settings\qtomlyc\My Documents\Attachments\CAR " & intRMA & " Spare Part Quote.doc"
-
-
' Reminder to change header date and RMA number
-
MsgBox "Header text not changed", vbOKOnly, "Create Quotation Document"
-
-
' Show the document to user in order to enter FAB numbers etc
-
appWord.Visible = True
-
-
' Dispose objects to free memory
-
Set appWord = Nothing
-
Set Range = Nothing
-
End Sub
however, i cannot change header text or text inside of a table with this code. how should i modify it to find and replace text inside these elements too?
best regards,
bm
6 3400 QVeen72 1,445
Recognized Expert Top Contributor
Hi,
Check this : -
Range.Find.Execute FindText:="XXXX", ReplaceWith:=intRMA,
-
Replace:=wdReplaceAll
-
REgards
Veena
unfortunately, nothing happened in the header...
QVeen72 1,445
Recognized Expert Top Contributor
Hi,
First Change the Variable Name, from Range to TRange as Range would be the resrved Word (if adding Office References),
Check some thing like this : -
Dim TRange As Range
-
Set TRange = Word.ActiveDocument.Content
-
With TRange.Find
-
.Text = "OLD_TEXT"
-
.Replacement.Text = "NEW_TEXT"
-
.Forward = True
-
.Wrap = wdFindAsk
-
.Format = False
-
.MatchCase = False
-
.MatchWholeWord = False
-
.MatchWildcards = False
-
.MatchSoundsLike = False
-
.MatchAllWordForms = False
-
End With
-
TRange.Find.Execute Replace:=wdReplaceAll
-
-
' WRITE CODE TO SAVE HERE..
-
Regads
Veena
Hi,
First Change the Variable Name, from Range to TRange as Range would be the resrved Word (if adding Office References),
Check some thing like this : -
Dim TRange As Range
-
Set TRange = Word.ActiveDocument.Content
-
With TRange.Find
-
.Text = "OLD_TEXT"
-
.Replacement.Text = "NEW_TEXT"
-
.Forward = True
-
.Wrap = wdFindAsk
-
.Format = False
-
.MatchCase = False
-
.MatchWholeWord = False
-
.MatchWildcards = False
-
.MatchSoundsLike = False
-
.MatchAllWordForms = False
-
End With
-
TRange.Find.Execute Replace:=wdReplaceAll
-
-
' WRITE CODE TO SAVE HERE..
-
Regads
Veena
still doesn't work. i got this code snippet from a collegue with even less vb knowledge than me and modified a little - could you tell me why the replace statement was in a loop to run 15 times?
just tilting this up a little...
as stated previously, i need help with how to access the text in the header and footer of a word document programatically, via VBA, from Outlook.
i also now need help with accessing a table, where i want to enter some information x number of times in a form and then write out a new table row for each entry.
does anyone know how to do this?
here is my working implementation (c#):
ApplicationClass wd = new ApplicationClass();
object fileName = t_filename;
object newTemplate = false;
object docType = 0;
object isVisible = true;
try
{
if(wd != null && wd.Documents != null)
{
document = wd.Documents.Open(ref fileName, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing);
}
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
bool b = wd.ActiveDocument.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Exists;
Range rg = wd.ActiveDocument.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
object Igaz = true;
object Hamis = false;
object replaceOpt = WdReplace.wdReplaceAll;
object stringToSearch = "<OWNER>";
object replaceWith = "ize";
rg.Find.Execute(ref stringToSearch, ref Igaz, ref Igaz, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref replaceWith, ref replaceOpt, ref missing, ref missing,
ref missing, ref missing);
wd.Visible = true;
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Arthur Shapiro |
last post by:
I'm the webmaster for a recreational organization. As part of one page of the
site, I have an HTML "Calendar at a Glance" of the organization's events for
the month. It's a simple table of a...
|
by: David Gartrell |
last post by:
Hi i'm trying to import an Excel Spreadsheet into Access2000 but the data
types for two of the fields in my imported table are being identified
incorrectly. Is there a way of using some VB code in...
|
by: Jozef |
last post by:
Hello,
Is there a way to change table permissions in VB Code? I can't seem to find
much that's concise in the help file. Here's the situation;
I have a table in the "data" portion of a split...
|
by: Ramesh |
last post by:
I am using a datalist control in my page and it has a header template.
In the header template I have a table control with table rows and
table cells. While the page is loading I am trying to change...
|
by: Bob Smith |
last post by:
I have existing word documents that we need to have the
data document reflect whether we're running in
development, test or production.
The data header is longer than 255 characters, so I cannot...
| |
by: deko |
last post by:
I have a popup form with a textbox that is bound to a memo field. I've been
warned about memo fields so I'm wondering if I should use this code. Is
there any risk with changing the form's...
|
by: Kevin K |
last post by:
Hi,
I'm having a problem with extracting text from a Word document using
StreamReader. As I'm developing a web application, I do NOT want the server
to make calls to Word. I want to simply...
|
by: Mo |
last post by:
I am trying to produce an Access report which behaves like a two
column table in Word. In other words each cell in column 1 contains a
label and each cell in column 2 contains data from a...
|
by: Cliff72 |
last post by:
I'm creating a database that will be uploading some text files into an
access table. The problem is that the text files have a header which
messes up my import specs. so what i have had to do is to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |