aarondewberry
IS-IT--Management
Hi all
This a follow up of the thread i started: thread705-1506980
I was given some code by Remou that allows me to open all .doc's in a folder, find an underlined Word, 'strProduct', find a value and add 300 to it, 'strPrice', then save the document with the strProduct and strPrice.
I have come into a problem though. Some of the .doc's have tables of data under the paragraph i want to interrogate and within these tables some of the cells have "_" in them. This is throwing out the IF statement at the end of the code. So when there is a doc with no word underlined and there is a table with, "_", in it, the strProduct value becomes nothing and gives a runtime error on save of the document.
Having said all that.
The underlined word will appear in the first two sentences only. So, is there a way of adapting the strProduct part of the code, to only look at the first 3 lines or the first two sentences of my doc. That way, the table would not come into play and if there is no underlined word, then the ELSE part of the statement would trigger.
Sorry all to revisit this again. But its a large thorn I need to get removed.
Any help will be much appreciated
Thanks
This a follow up of the thread i started: thread705-1506980
I was given some code by Remou that allows me to open all .doc's in a folder, find an underlined Word, 'strProduct', find a value and add 300 to it, 'strPrice', then save the document with the strProduct and strPrice.
I have come into a problem though. Some of the .doc's have tables of data under the paragraph i want to interrogate and within these tables some of the cells have "_" in them. This is throwing out the IF statement at the end of the code. So when there is a doc with no word underlined and there is a table with, "_", in it, the strProduct value becomes nothing and gives a runtime error on save of the document.
Having said all that.
The underlined word will appear in the first two sentences only. So, is there a way of adapting the strProduct part of the code, to only look at the first 3 lines or the first two sentences of my doc. That way, the table would not come into play and if there is no underlined word, then the ELSE part of the statement would trigger.
Sorry all to revisit this again. But its a large thorn I need to get removed.
Any help will be much appreciated
Thanks
Code:
Open .doc, pick out key words and save with key words
thread705-1506980
Sub ProcessWordDocs()
Dim wd As Object 'Word.Application
Dim doc As Object 'Word.Document
Dim aDoc
Dim strDoc As String
Dim strProduct As String
Dim strPrice As String
Dim strDocName
Dim rs As DAO.Recordset
Dim rsProc As DAO.Recordset
'On Error GoTo ProcessWordDocs_Error
Set wd = CreateObject("Word.Application")
wd.Visible = True
aDoc = Dir("C:\Docs\*.doc")
Do While aDoc <> ""
strDoc = "C:\Docs\" & aDoc
Set doc = wd.Documents.Open _
(FileName:=strDoc, AddToRecentFiles:=False)
[red] wd.selection.Find.ClearFormatting
wd.selection.Find.Font.Underline = 1 'wdUnderlineSingle
wd.selection.Find.Text = ""
wd.selection.Find.Wrap = 1 'wdFindContinue
wd.selection.Find.Execute
If wd.selection.Find.Found Then
strProduct = wd.selection.range
Else
strProduct = "NONE: " & aDoc
End If [/red]
wd.selection.Find.ClearFormatting
wd.selection.Find.Text = "Selling to you for $"
wd.selection.Find.Wrap = 1 'wdFindContinue
wd.selection.Find.Execute
'wdWord=2, wdExtend=1
If wd.selection.Find.Found Then
wd.selection.MoveRight Unit:=2, Count:=1, Extend:=1
strPrice = Mid(wd.selection.range, InStr(wd.selection.range, "$") + 1)
strDocName = "C:\Docs\Proper\" & strProduct & "_$" & strPrice & ".doc"
strPrice = strPrice + 300
wd.selection.range.Text = "Selling to you for $" & strPrice
doc.saveas strDocName
Else
strPrice = "NONE: " & aDoc
End If
doc.Close
Debug.Print strProduct, strPrice
aDoc = Dir
Loop
Set doc = Nothing
wd.Quit
Set wd = Nothing
End Sub