473,320 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

format tagging in word documents

Hi,

I have a following code to find the format tags in word document and insert some text over there. It works perfectly when I run only a single procedure individually i.e. commenting a call to either TagBoldWords or TagItalicWords.
Can anybody help me as to how we can go for it.

Thanks & Regards,
Sameer


Dim doc As New Word.Document
Dim appword As New Word.Application
Private Sub Command1_Click()
Set appword = New Word.Application

Set doc = appword.Documents.Open("C:\AAA.doc")

doc.Content.Select
TagBoldWords
TagItalicWords ' if it is commented it works perfect, but i want both
' these procedures to be used simultaneously

doc.SaveAs "C:\BBB.doc"
doc.Close
Set doc = Nothing

appword.Quit
Set appword = Nothing
Unload Me
End Sub


Sub TagBoldWords()
Selection.HomeKey Unit:=wdStory
With Selection.Find
.Font.Bold = True
Do While (.Execute(findtext:="", Forward:=True) = True) = True
With Selection
.InsertBefore Text:="<b>"
.Collapse Direction:=wdCollapseEnd
'.Font.Bold = False
.TypeText Text:="</b>"
.Collapse Direction:=wdCollapseEnd
End With
Loop
End With
End Sub


Sub TagItalicWords()
Selection.HomeKey Unit:=wdStory
With Selection.Find
.Font.Italic = True
Do While (.Execute(findtext:="", Forward:=True) = True) = True
With Selection
.InsertBefore Text:="<i>"
.Collapse Direction:=wdCollapseEnd
.Font.Italic = False
.TypeText Text:="</i>"
.Collapse Direction:=wdCollapseEnd
End With
Loop
End With
End Sub
Oct 12 '06 #1
3 1317
willakawill
1,646 1GB
TagBoldWords
TagItalicWords ' if it is commented it works perfect, but i want both
' these procedures to be used simultaneously
You might try adding DoEvents in between these two calls:

TagBoldWords
DoEvents
TagItalicWords
Oct 12 '06 #2
You might try adding DoEvents in between these two calls:

TagBoldWords
DoEvents
TagItalicWords
Thanks for the reply. I had tried that also but it didn't work, so I left it out.
Oct 13 '06 #3
willakawill
1,646 1GB
Thanks for the reply. I had tried that also but it didn't work, so I left it out.
Yeah. You need to give Word time to complete the process.
Perhaps, after DoEvents, you can put in a timer or loop to create a time gap between the two calls.

For i = 1 To 1000000
stWasteTime = "Just wasting time"
Next i
Oct 13 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Phil Rutter | last post by:
Hello All, I have about 700 word documents that have 2 tables one is static 4 colums x 5 rows the other is 5 colums x rows ranging from 2 to 100 what i wolud like to do is open the word doc....
4
by: Daniel | last post by:
Hello, i have a problem with the word automation from c#. First, i want to mention, that i don't have any dependencies from word in my c#-project, i want to use the system.reflection model to...
0
by: mharris | last post by:
I need help with merging two Word documents into one through C# code. The problem isn't so much getting the documents put into one as it is maintaining the appropriate formatting, or rather...
0
by: Steve | last post by:
I am noticing a problem when interfacing with Word through my C# code. What I am trying to do is enumerate through the documents currently open in Word. I have noticed issues with this on both...
7
by: Dave | last post by:
Apologies for the newbie question. I have created a vb.net program for my company that is designed to work with Word Templates (about forty of them that we commonly use) that are selected by the...
0
by: Vasiliy | last post by:
Hi all! I'm developing an application to manage word templates and documents. Documents are stored in database, so when user wants to edit a document i make a local copy of this document and then...
0
by: R1gg4 | last post by:
Hi all, I currently have a VB.NET application that interfaces with Word 2003 to produce documents from templates substituting the data in the template to form the document. This is all working...
5
by: Carstonio | last post by:
I use ASP to display links to Word documents on an intranet. Is there a way in ASP to do text searches on the documents' contents? I want the results to have the link to the Word document plus two...
2
by: Derek Hart | last post by:
I am using late bound Microsoft Word integration with a vb.net winforms application. If I run code such as the following: Dim objWord As Object Dim objWrdDoc As Object Dim count As Integer...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.