This issue has been discussed before but I'm raising it again since I haven't yet found a real solution.
I have a regular need to remove extraneous text from a comma delimited text file prior to importing the data, which often contains occassional asterisks and quotation marks in divers places. I have a Word macro which removes these quite efficiently but I would very much like to have this problem solved within an Access module that accomplishes the same result without having to call the Macro.
I have searched the Microsoft KB, Microsoft Automation 97 Help file, Access VBA Help file, Word VBA help file. Many methods are suggested such as this found in the Object browser under Word,Range,Find:
This example replaces "Hello" with "Goodbye" in the active document.
Set myRange = ActiveDocument.Content
With myRange.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "Hello"
.Replacement.Text = "Goodbye"
.Execute Replace:=wdReplaceAll
End With
and this simple offering also found via the Word 8 object library :
This example finds all occurrences of the word "hi" in the active document and replaces each occurrence with "hello."
Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="hi", ReplaceWith:="hello", Replace:=wdReplaceAll
Both of these and several others I had a go with failed. Most caused a Fatal Error message and Access closed. In particular Access had no truck with the line .Clearformatting
If anyone has a neat and reliable VBA solution for finding and removing specified text that does not involve running a Word macro from Access I would be very interested.
Rod
I have a regular need to remove extraneous text from a comma delimited text file prior to importing the data, which often contains occassional asterisks and quotation marks in divers places. I have a Word macro which removes these quite efficiently but I would very much like to have this problem solved within an Access module that accomplishes the same result without having to call the Macro.
I have searched the Microsoft KB, Microsoft Automation 97 Help file, Access VBA Help file, Word VBA help file. Many methods are suggested such as this found in the Object browser under Word,Range,Find:
This example replaces "Hello" with "Goodbye" in the active document.
Set myRange = ActiveDocument.Content
With myRange.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "Hello"
.Replacement.Text = "Goodbye"
.Execute Replace:=wdReplaceAll
End With
and this simple offering also found via the Word 8 object library :
This example finds all occurrences of the word "hi" in the active document and replaces each occurrence with "hello."
Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="hi", ReplaceWith:="hello", Replace:=wdReplaceAll
Both of these and several others I had a go with failed. Most caused a Fatal Error message and Access closed. In particular Access had no truck with the line .Clearformatting
If anyone has a neat and reliable VBA solution for finding and removing specified text that does not involve running a Word macro from Access I would be very interested.
Rod