-
Apr 22nd, 2022, 08:57 AM
#1
Thread Starter
New Member
[RESOLVED] VB for Applications - MS Word - String.Subtring(3, 7) not working
I am attempting to get a word file to automatically save a filename with a part of the path in the name. I am using the String.Substring method and I keep getting an "Invalid qualifier" error. The code is below:
Code:
Dim thisDate As String
thisDate = Format(Now, "dddd, d MMM yyyy")
Dim myPath As String
Dim jobNum As String
myPath = ActiveDocument.Path
'myPath = "asdfghjklqwertyuiopzxcvbnm"
MsgBox myPath
'Save Substring with the Job Number to identify the job
jobNum = myPath.Substring(3, 7)
'MsgBox myPath.Substring(3, 7)
MsgBox jobNum
ActiveDocument.SaveAs2 (ActiveDocument.Path & "" & thisDate)
'Application.ActiveDocument.SaveAs2 ("Test")
'ActiveDocument.SaveAs (Application.ActiveDocument.Path)
End Sub
Any thoughts. Every example I look at implies it should work. I have even made another string to test with and I get the same error.
Thanks for your help.
Last edited by dday9; Apr 22nd, 2022 at 09:23 AM.
Reason: Added BB Code
-
Apr 22nd, 2022, 09:23 AM
#2
Re: VB for Applications - MS Word - String.Subtring(3, 7) not working
Moderator Actions: Moved to Office Development, which is for questions regarding Microsoft Office Automation. This can include VSTO, VSTA, and VBA questions.
-
Apr 22nd, 2022, 05:49 PM
#3
Re: VB for Applications - MS Word - String.Subtring(3, 7) not working
I don't see where you are actually using the jobNum as part of the file name.
Have you checked to see what thisDate actually contains?
Check to see what ActiveDocument.Path & thisDate would be. Is it a legal file path and name?
You do not need the '& "" ' since it does not do anything.
-
Apr 22nd, 2022, 06:05 PM
#4
Thread Starter
New Member
Re: VB for Applications - MS Word - String.Subtring(3, 7) not working
Originally Posted by jdc2000
I don't see where you are actually using the jobNum as part of the file name.
Have you checked to see what thisDate actually contains?
Check to see what ActiveDocument.Path & thisDate would be. Is it a legal file path and name?
You do not need the '& "" ' since it does not do anything.
I was using jobNum before I began to troubleshoot and test the logic. I have comeback to it. The variable thisDate contains the date. The & "" is unnecessary but it previously contained a backslash, not sure why I removed it. I was able to successfully get this working using jobNum = Right(myPath, 15) in conjunction with jobNum = Left(jobNum, 7) to successfully extract the information I needed from the path variable. I don't think String.Substring works in VBA.
Thank you for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|