wildcard problems with word 97

A

Agent Mulder

Hello all,
first of all, thanks for reading and all help is really appreciated!

In a nutshell, I need to know the correct way to call a wildcard in
word 1997.

I am trying to get this word application to work in the 1997 version
(it was originally written for the newest version, 2000 I think) and
the only thing that fails is my trying to call a wildcard. a snippet
with this wildcard follows:

img_file_name = acts_no_b1 + acts_no_b2 + ".JPG"
search_file_name = acts_no_name + "_ " + "???.JPG"

I have tried the three question marks, and a simple * like:
search_file_name = acts_no_name + "_ " + "*.JPG"
or
search_file_name = acts_no_name + "_ " + "***.JPG"

and other more silly things,but nothing seems to work.
The question marks represent the three digit unique image suffix which
is constructed by the app.

the image file names that are searched for would be something like
this:

52134534549_001.JPG
52134534549_002.JPG
52134534549_003.JPG

here is all of the code:

Public Sub Main()
WordBasic.StartOfDocument
'removed to allow autocall for passes
'WordBasic.EditFind Find:="^pTHIS", Direction:=0, MatchCase:=0,
WholeWord:=0, PatternMatch:=0, SoundsLike:=0, Format:=0, Wrap:=2

WordBasic.WW7_EditGoTo Destination:="msb_signature"
WordBasic.CharLeft 1
WordBasic.InsertPara
WordBasic.Underline
WordBasic.Insert "DISCUSSION"
WordBasic.Underline
WordBasic.Insert ":"
WordBasic.InsertPara

WordBasic.StartOfDocument
WordBasic.EditFind Find:="Vendor:", Direction:=0, MatchCase:=1,
WholeWord:=0, PatternMatch:=0, SoundsLike:=0, Format:=0, Wrap:=2
WordBasic.Insert "Submitter:"

WordBasic.StartOfDocument
Selection.GoTo What:=wdGoToBookmark, Name:="amb_ccs"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Tables(1).Select
Selection.Delete Unit:=wdCharacter, Count:=1

'Image test
' Get the last 7 digits of the master acts no
WordBasic.StartOfDocument
Selection.GoTo What:=wdGoToBookmark, Name:="msb_trstart"

Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.MoveRight Unit:=wdCharacter, Count:=13, Extend:=wdExtend
acts_no_dash_par = Selection.Text

acts_no_a = Left(acts_no_dash_par, 4)
acts_no_b1 = Left(acts_no_b, 3)
acts_no_b2 = Right(acts_no_b, 4)

acts_no_name = acts_no_a + acts_no_b1 + acts_no_b2

'############################################


img_file_name = acts_no_b1 + acts_no_b2 + ".JPG"
search_file_name = acts_no_name + "_001.JPG"
' ans = MsgBox("File is " & search_file_name & ".", vbOKOnly,
"File")
Selection.ExtendMode = False
' See if the image exists in R:\Images\TRU
no_of_images = 1
image_found = 0
' Search for image filenames without a dash first.
With Application.FileSearch
.NewSearch
.LookIn = "R:\Images\TRU"
.FileName = search_file_name
.SearchSubFolders = False
.MatchTextExactly = True
End With
If Application.FileSearch.Execute = 0 Then
' Search for image filenames with a dash.
With Application.FileSearch
.NewSearch
.LookIn = "R:\Images\TRU"
''.FileName = img_file_name_dash
.FileName = img_file_name
.SearchSubFolders = False
.MatchTextExactly = True
End With
'############################################
If Application.FileSearch.Execute > 0 Then
image_found = 1
''img_file_name = img_file_name_dash
End If
Else
' Count the number of files found with this acts number in
case there are mutiple
' images.
no_of_images = Application.FileSearch.FoundFiles.Count
image_found = 1
End If
If image_found = 1 Then
For image_loop = 1 To no_of_images
If no_of_images > 1 Then
img_file_name =
Application.FileSearch.FoundFiles(image_loop)
End If
' ans = MsgBox("Found the image.", vbOKOnly, "Image")
' Go to the end of the document
Selection.EndKey Unit:=wdStory, Extend:=wdMove

' Insert a page/section break
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.EndKey Unit:=wdStory, Extend:=wdMove
' Stop print "First Page" from tray 1.
With ActiveDocument.Range(Start:=Selection.Start,
End:=ActiveDocument. _
Content.End).PageSetup
.FirstPageTray = wdPrinterLowerBin
.OtherPagesTray = wdPrinterLowerBin
End With
' Go to the header and delete unnecessary information
With ActiveWindow.View
.SeekView = wdSeekCurrentPageHeader
End With

Selection.HeaderFooter.LinkToPrevious = False

With ActiveWindow.View
.Type = wdPageView
.SeekView = wdSeekMainDocument
End With

If image_loop = 1 Then
' Copy the Master ACTS Number
Selection.GoTo What:=wdGoToBookmark,
Name:="msb_trstart"
Selection.ExtendMode = True
Selection.GoTo What:=wdGoToBookmark, Name:="msb_trend"
Selection.Range.Copy
Selection.ExtendMode = False
Selection.EndKey Unit:=wdStory, Extend:=wdMove
With ActiveWindow.View
.SeekView = wdSeekCurrentPageHeader
End With

Selection.Paragraphs.Alignment = wdAlignParagraphRight
Selection.TypeText Text:="TOYS " + Chr(34) + "R" +
Chr(34) + " US CORPORATION - USA"
Selection.InsertParagraphAfter
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Technical Report: "
WordBasic.EndOfLine
WordBasic.EditPaste
WordBasic.Bold
WordBasic.FontSize 9
WordBasic.InsertPara
'Selection.Range.Paste
'Selection.Font.Bold = True
'WordBasic.InsertPara
With Selection.Font
.Bold = False
.Size = 9
End With
If rptdate_flag = 0 Then
Selection.InsertDateTime DateTimeFormat:="MMMM d,
yyyy", InsertAsField:=False
Else
Selection.TypeText Text:=RptDate
End If
WordBasic.InsertPara
WordBasic.Insert "Page "
WordBasic.InsertField Field:="PAGE \* MERGEFORMAT"
WordBasic.Insert " of "
WordBasic.InsertField Field:="NUMPAGES \*
MERGEFORMAT"
WordBasic.InsertPara
WordBasic.LeftPara
WordBasic.InsertPara
WordBasic.InsertPara
Selection.TypeText Text:="Sample Image"
WordBasic.InsertPara
WordBasic.ViewHeader
WordBasic.StartOfDocument
' Add required information to header

' Return to main document and insert the image
With ActiveWindow.View
.Type = wdPageView
.SeekView = wdSeekMainDocument
End With
End If
Selection.EndKey Unit:=wdStory, Extend:=wdMove
ChangeFileOpenDirectory "R:\Images\TRU\"
'Selection.InlineShapes.AddPicture
FileName:="R:\Images\TRU\" & img_file_name, _
' LinkToFile:=False, SaveWithDocument:=True
Selection.InlineShapes.AddPicture FileName:=img_file_name,
_
LinkToFile:=False, SaveWithDocument:=True
Selection.ParagraphFormat.Alignment =
wdAlignParagraphCenter
Next image_loop
Selection.HomeKey Unit:=wdStory, Extend:=wdMove
Application.ScreenUpdating = True
End If

End Sub


best regards,
John
 
W

Word Heretic

G'day (e-mail address removed) (Agent Mulder),

did you actually set find.matchwildcards = true?


(e-mail address removed) (Agent Mulder) was spinning this yarn:
Hello all,
first of all, thanks for reading and all help is really appreciated!

In a nutshell, I need to know the correct way to call a wildcard in
word 1997.

I am trying to get this word application to work in the 1997 version
(it was originally written for the newest version, 2000 I think) and
the only thing that fails is my trying to call a wildcard. a snippet
with this wildcard follows:

img_file_name = acts_no_b1 + acts_no_b2 + ".JPG"
search_file_name = acts_no_name + "_ " + "???.JPG"

I have tried the three question marks, and a simple * like:
search_file_name = acts_no_name + "_ " + "*.JPG"
or
search_file_name = acts_no_name + "_ " + "***.JPG"

and other more silly things,but nothing seems to work.
The question marks represent the three digit unique image suffix which
is constructed by the app.

the image file names that are searched for would be something like
this:

52134534549_001.JPG
52134534549_002.JPG
52134534549_003.JPG

here is all of the code:

Public Sub Main()
WordBasic.StartOfDocument
'removed to allow autocall for passes
'WordBasic.EditFind Find:="^pTHIS", Direction:=0, MatchCase:=0,
WholeWord:=0, PatternMatch:=0, SoundsLike:=0, Format:=0, Wrap:=2

WordBasic.WW7_EditGoTo Destination:="msb_signature"
WordBasic.CharLeft 1
WordBasic.InsertPara
WordBasic.Underline
WordBasic.Insert "DISCUSSION"
WordBasic.Underline
WordBasic.Insert ":"
WordBasic.InsertPara

WordBasic.StartOfDocument
WordBasic.EditFind Find:="Vendor:", Direction:=0, MatchCase:=1,
WholeWord:=0, PatternMatch:=0, SoundsLike:=0, Format:=0, Wrap:=2
WordBasic.Insert "Submitter:"

WordBasic.StartOfDocument
Selection.GoTo What:=wdGoToBookmark, Name:="amb_ccs"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Tables(1).Select
Selection.Delete Unit:=wdCharacter, Count:=1

'Image test
' Get the last 7 digits of the master acts no
WordBasic.StartOfDocument
Selection.GoTo What:=wdGoToBookmark, Name:="msb_trstart"

Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.MoveRight Unit:=wdCharacter, Count:=13, Extend:=wdExtend
acts_no_dash_par = Selection.Text

acts_no_a = Left(acts_no_dash_par, 4)
acts_no_b1 = Left(acts_no_b, 3)
acts_no_b2 = Right(acts_no_b, 4)

acts_no_name = acts_no_a + acts_no_b1 + acts_no_b2

'############################################


img_file_name = acts_no_b1 + acts_no_b2 + ".JPG"
search_file_name = acts_no_name + "_001.JPG"
' ans = MsgBox("File is " & search_file_name & ".", vbOKOnly,
"File")
Selection.ExtendMode = False
' See if the image exists in R:\Images\TRU
no_of_images = 1
image_found = 0
' Search for image filenames without a dash first.
With Application.FileSearch
.NewSearch
.LookIn = "R:\Images\TRU"
.FileName = search_file_name
.SearchSubFolders = False
.MatchTextExactly = True
End With
If Application.FileSearch.Execute = 0 Then
' Search for image filenames with a dash.
With Application.FileSearch
.NewSearch
.LookIn = "R:\Images\TRU"
''.FileName = img_file_name_dash
.FileName = img_file_name
.SearchSubFolders = False
.MatchTextExactly = True
End With
'############################################
If Application.FileSearch.Execute > 0 Then
image_found = 1
''img_file_name = img_file_name_dash
End If
Else
' Count the number of files found with this acts number in
case there are mutiple
' images.
no_of_images = Application.FileSearch.FoundFiles.Count
image_found = 1
End If
If image_found = 1 Then
For image_loop = 1 To no_of_images
If no_of_images > 1 Then
img_file_name =
Application.FileSearch.FoundFiles(image_loop)
End If
' ans = MsgBox("Found the image.", vbOKOnly, "Image")
' Go to the end of the document
Selection.EndKey Unit:=wdStory, Extend:=wdMove

' Insert a page/section break
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.EndKey Unit:=wdStory, Extend:=wdMove
' Stop print "First Page" from tray 1.
With ActiveDocument.Range(Start:=Selection.Start,
End:=ActiveDocument. _
Content.End).PageSetup
.FirstPageTray = wdPrinterLowerBin
.OtherPagesTray = wdPrinterLowerBin
End With
' Go to the header and delete unnecessary information
With ActiveWindow.View
.SeekView = wdSeekCurrentPageHeader
End With

Selection.HeaderFooter.LinkToPrevious = False

With ActiveWindow.View
.Type = wdPageView
.SeekView = wdSeekMainDocument
End With

If image_loop = 1 Then
' Copy the Master ACTS Number
Selection.GoTo What:=wdGoToBookmark,
Name:="msb_trstart"
Selection.ExtendMode = True
Selection.GoTo What:=wdGoToBookmark, Name:="msb_trend"
Selection.Range.Copy
Selection.ExtendMode = False
Selection.EndKey Unit:=wdStory, Extend:=wdMove
With ActiveWindow.View
.SeekView = wdSeekCurrentPageHeader
End With

Selection.Paragraphs.Alignment = wdAlignParagraphRight
Selection.TypeText Text:="TOYS " + Chr(34) + "R" +
Chr(34) + " US CORPORATION - USA"
Selection.InsertParagraphAfter
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Technical Report: "
WordBasic.EndOfLine
WordBasic.EditPaste
WordBasic.Bold
WordBasic.FontSize 9
WordBasic.InsertPara
'Selection.Range.Paste
'Selection.Font.Bold = True
'WordBasic.InsertPara
With Selection.Font
.Bold = False
.Size = 9
End With
If rptdate_flag = 0 Then
Selection.InsertDateTime DateTimeFormat:="MMMM d,
yyyy", InsertAsField:=False
Else
Selection.TypeText Text:=RptDate
End If
WordBasic.InsertPara
WordBasic.Insert "Page "
WordBasic.InsertField Field:="PAGE \* MERGEFORMAT"
WordBasic.Insert " of "
WordBasic.InsertField Field:="NUMPAGES \*
MERGEFORMAT"
WordBasic.InsertPara
WordBasic.LeftPara
WordBasic.InsertPara
WordBasic.InsertPara
Selection.TypeText Text:="Sample Image"
WordBasic.InsertPara
WordBasic.ViewHeader
WordBasic.StartOfDocument
' Add required information to header

' Return to main document and insert the image
With ActiveWindow.View
.Type = wdPageView
.SeekView = wdSeekMainDocument
End With
End If
Selection.EndKey Unit:=wdStory, Extend:=wdMove
ChangeFileOpenDirectory "R:\Images\TRU\"
'Selection.InlineShapes.AddPicture
FileName:="R:\Images\TRU\" & img_file_name, _
' LinkToFile:=False, SaveWithDocument:=True
Selection.InlineShapes.AddPicture FileName:=img_file_name,
_
LinkToFile:=False, SaveWithDocument:=True
Selection.ParagraphFormat.Alignment =
wdAlignParagraphCenter
Next image_loop
Selection.HomeKey Unit:=wdStory, Extend:=wdMove
Application.ScreenUpdating = True
End If

End Sub


best regards,
John

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
Email: (e-mail address removed)
Products: http://www.geocities.com/word_heretic/products.html
Spellbooks: 728 pages of dump left and dropping...

The VBA Beginner's Spellbook: For all VBA users.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top