Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable used to create directory

Status
Not open for further replies.

sigrist

Programmer
Apr 24, 2011
2
I am trying to export a Name: field from the current Word document and use it to create a directory on c:.

I have tried in Word 2007 and 2010.

I get a Run-time error '76': Path not found.

I cannot find the bug in my code, can you?

Thanks

Daniel




Sub CreateDirectory()
Mkdir("c:/" & ThatID("Name:"))
End Sub


Public Function ThatID(xx As String) As String
Dim ID As String

Selection.HomeKey Unit:=wdStory

Selection.Find.ClearFormatting
With Selection.Find
.Text = xx
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Copy

ID = Selection

Selection.EndKey Unit:=wdStory

ThatID = ID

End Function
 
I'm not sure if this is the bug you are looking for, but I would try changing
Code:
Mkdir("c:[COLOR=red]/[/color]" & ThatID("Name:"))
to
Code:
Mkdir("c:\" & ThatID("Name:"))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top