saveas syntax ??

saveas syntax ??

Anonymous
Not applicable
380 Views
2 Replies
Message 1 of 3

saveas syntax ??

Anonymous
Not applicable
hello everyone,

I am trying to run a program that creates a folder then saves the current drawing into that folder.
It appears that I am having a problem with ThisDrawing.SaveAs syntax. I'm getting an "invalid file name" error. Could anyone help???

/code/

Option Explicit

' create a folder in ok laser
Const FolderPath = "R:\POSTIT\FIXTURES\FIX_ENG\MACHINE\OK_LASER\"
Private Sub CommandButton1_Click()
Dim strFolderPath As String
Dim foldername As String
Dim dwgName As String

foldername = Right(ThisDrawing.Path, Len(ThisDrawing.Path) - 67)
strFolderPath = FolderPath & "\" & foldername
dwgName = Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 4)

If Dir(strFolderPath, vbDirectory) = "" Then
MkDir strFolderPath
End If

ThisDrawing.SaveAs strFolderPath & dwgName, acR15_dxf
ThisDrawing.Save

End Sub
/code/

I appreciate any advice.
End Sub
0 Likes
381 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Firstly, because all the naming, and the results from the naming, are dependent on where you are working from, pathwise, as well as the current name of the drawing, which will vary, that the results from this code cannot be checked or reproduced. And Im guessing the errors you are getting are much the same. So Im guessing that your problem is the name you trying to save to, or the name of the directory you are trying to create.


>>Const FolderPath = "R:\POSTIT\FIXTURES\FIX_ENG\MACHINE\OK_LASER\"
You defined a constant, but never used it anywhere

>>foldername = Right(ThisDrawing.Path, Len(ThisDrawing.Path) - 67)
What is it you are trying to do here? You are using a "hard" number, but the path name could be variable.
You are stripping out 67 chararacters from a pathname? It seems you should have your Constant defined to "foldername"

>>strFolderPath = FolderPath & "\" & foldername
You have to be careful here: some times the path comes back without the last slash. I usually check to see if its
missing, and only add it then, like this:

If Right$(strFolderPath,1) <> "\" then strFolderPath=strFolderPath & "\"

So, you are taking the last part of a path, and adding it to the end of an existing path? You'lll end up with a directory structure like this:
C:\Temp\Temp\Temp\Temp\Temp\Temp\Temp\ (etc, etc)- is this redundant naming what you are looking for?

All this confusion, BTW, can be eliminated with one VBA command:

Debug.Print

merely print out to the debug window what the result of each of your string commands are doing, so you arent "building" on the erroneous results from the last command.

For instance, after your command "= Right(ThisDrawing.Path, Len(ThisDrawing.Path) - 67)", add the following:
Debug.print foldername

then check the results to see that "foldername" is being created correctly.
0 Likes
Message 3 of 3

Anonymous
Not applicable
rocheey,

Thanks for the help. I was able to figure it out. That "Debug.Print" command kept me sane .

thanks again
0 Likes