With ActiveDocument
Dim CaseNumber As String
Dim DocFileName As String
CaseNumber = ActiveDocument.Bookmarks("SaveFileNumber").Range.Text
DocFileName = ActiveDocument.Bookmarks("DocFileName").Range.Text
With Dialogs(wdDialogFileSaveAs)
.Name = "\\lvco-dc\prosecutor\CaseDocs\" & CaseNumber & "\" &
DocFileName
.Show
End With
End With
The name of the file folder that I want to search for is represented by the
variable called CaseNumber. Currently, if the folder for the CaseNumber
variable doesn't exist, then the SaveAs dialog box opens up at the CaseDocs
folder. Instead of having that happen, I would like to create a new folder
in CaseDocs with that new folder's name being supplied by the CaseNumber
variable.
Any assistance would be greatly appreciated.
Roger
Hi Roger,
The easiest way to implement this is to use the FileScriptingObject.
It's helpful but not required to first click Tools > References and check
the Microsoft Scripting Runtime item. That gives you IntelliSense support
and access to the Help topics.
Then add something like this to your code before the Dialogs() statement:
Dim FSO As FileSystemObject
Dim NewDir As String
Set FSO = CreateObject("Scripting.FileSystemObject")
NewDir = "\\lvco-dc\prosecutor\CaseDocs\" & CaseNumber
If Not FSO.FolderExists(NewDir) Then
FSO.CreateFolder NewDir
End If
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Roger
"Jay Freedman" <jay.fr...@verizon.net> wrote in message
news:OoHGgnbd...@TK2MSFTNGP09.phx.gbl...
> It's helpful but not required to first click Tools > References and check
> the Microsoft Scripting Runtime item.
It *is* required so the FileSystemObject type will be defined.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Roger
"Jay Freedman" <jay.fr...@verizon.net> wrote in message
news:uEbmlv7i...@tk2msftngp13.phx.gbl...
Now that I've added the auto folder creation capability, I'm concerned what
will happen if a user edits the contents of the bookmark and changes the
value to something that doesn't match the specified standard.
If this is possible, I'd like to see an example of how to accomplish it?
Thanks.
"Jay Freedman" <jay.fr...@verizon.net> wrote in message
news:uEbmlv7i...@tk2msftngp13.phx.gbl...
The following example will accept numbers like 4.7 or 99.4 and will
reject everything else. The Like operator is a pattern-matching
function, and the expression that follows it is the pattern.
Dim CaseNumber As String
Dim DocFileName As String
Dim msg As String
msg = "The text you entered for the case number is not " & _
"in the right format. Please enter the correct number."
With ActiveDocument
' first check whether the bookmark exists
' (it could have been deleted)
If .Bookmarks.Exists("SaveFileNumber") Then
CaseNumber = .Bookmarks("SaveFileNumber").Range.Text
End If
' check that the string has the right format
Do While Not ((CaseNumber Like "#.#") Or _
(CaseNumber Like "##.#"))
' if not, ask user for correct value
CaseNumber = InputBox(msg, "Error")
If CaseNumber = "" Then Exit Sub ' canceled
Loop
DocFileName = .Bookmarks("DocFileName").Range.Text
End With
If the correct format is more complicated, the code that validates the
bookmark could be put into a separate function that just returns True
(the value is OK) or False (it doesn't match the requirement).
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
As for the CaseNumber format it's always ####-AB-######. By that I mean
it's always comprised of "Year" "-" "2 letter CaseType" "-" "6 digit number"
as in 2005-CT-000015 for example. I'm guessing that would require calling a
function to run this validation test. I've never done that before.
Roger
"Jay Freedman" <jay.fr...@verizon.net> wrote in message
news:0mdrd1td6920vl68j...@4ax.com...
Actually, that pattern is easier to check than one that might have a
variable number of characters. In the last macro I posted, replace the
lines
> Do While Not ((CaseNumber Like "#.#") Or _
> (CaseNumber Like "##.#"))
with this:
Do While Not (CaseNumber Like "####-[A-Z][A-Z]-######")
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
"Jay Freedman" <jay.fr...@verizon.net> wrote in message
news:2dstd1t82fmjaetsu...@4ax.com...