I am currently generating a solidworks part file name from a text document for a batch "rename" of the documents. This assigns sequential numbers to them which i then save each part in a folder as. I have been trying to figure out a method for the new file names to be referenced in the assembly they were a part of.
For saving the document I am using :
swModel.SaveAs3 "" & FileName & "", 0, 0
I have no issue creating all the files in a batch but I could not seem to find a method of apply this save in such a way that any open documents that it is referenced in change to referencing the new part name.
Edit: I figured out a serviceable solution using some of the information held in this link:
help.solidworks
Using the pack and go functionality in solidworks avoids having to deal with the references as they are already handled by the process itself Hope this helps.
Try the below approach:
Dim FileName As String
FileName = "blablabla" & Variable & "blablabla"
swModel.SaveAs3 ("C:\User\Username\Desktop" + FileName + ".SLDPRT", 0, 1)
Variable = Variable + 1
'continue with your loop
Related
I use Foxit Phantompdf, the complete version and ACCESS.
In our program, we have to save multiple pdf files, some of them should be merged in single files when saved.
Here is the code I use;
Dim phApp As PhantomPDF.Application
Dim n1 As String
Dim n2 As String
n1 = "c:\Temp\F3769-190136-GROUPE OCÉAN.pdf"
n2 = "c:\Temp\f3769-190136-GROUPE OCÉAN- facture.pdf"
Set phApp = CreateObject("PhantomPDF.Application")
Dim phCreator As PhantomPDF.Creator
Set phCreator = phApp.Creator
***'Call phCreator.CombineFiles("c:\Temp\F3769-190136-GROUPE OCÉAN.pdf|c:\Temp\f3769-190136-GROUPE OCÉAN- facture.pdf", "c:\Temp\F3769-190136-GROUPE OCÉAN.pdf", COMBINE_ADD_CONTENTS)***
Call phCreator.CombineFiles("""c:\Temp\" & n1 & "|'" & n2 & """" & ", " & """c:\Temp\F3769-190136-GROUPE OCÉAN.pdf"""" &", COMBINE_ADD_CONTENTS)
phApp.Exit
When I try it with the complete files names (in bold) the code works perfectly.
However, when I try to use variables, I get a
"Argument not optional"
error.
Can somebody help me ?
Thanks
Your string definitions in call line is incorrect.
You have defined n1 and n2 with the c:\temp already, and in your string conversion you add this again. I do not know if this is the route cause to your issue.
Furthermore I do not know the actual needed syntax for this phcreator.combine()
But is it not possible using only:
call pHcreator.combine(n1 & "|" & n2, …
The 'Argument not option' might imply you should add another input to your pHcreator, I would guess it could have something to do with FOXIT's combine function page settings. Try adding a input variable integer at the end of the function maybe?
But the fact that it works when writing strings in clear text would maybe suggest that the string manipulations is not correct?
I'm not a vba professional, but interested in the outcome, working myself with Foxit and also want to combine with vba. I'm currently not using version 9 som I seem to be out of luck, and only upgrading it I know what I want to do is possible.
I tried it, but got the same error message. So I took advantage of the fact that the function works when the file names are in plain text. I copied the files to be merged in a temporary folder and rename them. The renamed files are the then used in the merge function. It works perfectly, but Foxit adds a table of content page, and I don't know, yet, how to remove it. Here is my solution:
Private Sub Command4_Click()
Dim addi As String 'file to be merged to main file
Dim princi As String 'main file
Dim phApp As PhantomPDF.Application
'A temporary folder, in this case c:\t2, should be present
'In this example c:\Temp is the working folder
addi = "c:\Temp\filetomerge.pdf" 'full path of file to be merged
princi = "c:\Temp\mainfile.pdf" 'full path of main file
'fadd,pdf and fmain.pdf are the temporay files used in Foxit's function
FileCopy addi, "c:\t2\fadd.pdf" 'temporary file to be merged in temporary folder
FileCopy princi, "c:\t2\fmain.pdf" 'temporary main file in temporary folder
'Merge action
Set phApp = CreateObject("PhantomPDF.Application")
Dim phCreator As PhantomPDF.Creator
Set phCreator = phApp.Creator
Call phCreator.CombineFiles("c:\t2\fmain.pdf|c:\t2\fadd.pdf", "c:\t2\fmain.pdf", COMBINE_ADD_CONTENTS)
phApp.Exit
'Save merged file in working folder under main file name
Kill princi
FileCopy "c:\t2\fmain.pdf", princi
'delete temporary files
Kill "c:\t2\fadd.pdf"
Kill "c:\t2\fmain.pdf"
End Sub
Example i have picture folder located at
Dim path As String = "D:\Student Picture\Student-" + textbox_Search.Text + ".jpg"
Something like that. now i want the the picture folder to just paste it in debug folder can i call it without the drive letter something like this ??
Dim path As String = "\bin\debug\Student Picture\Student-" + textbox_Search.Text + ".jpg"
Its not working. The reason why i want to achieve this is example i use my program in another computer but the other computer don't have drive D: then my program will not work because in my code all of the student picture declared in drive D: thank you so much.
You can get the application startup path and create the folder in either the Debug or Release locations, depending which you're running. The folder would be created within the directory in which the end-user runs the compiled application.
Dim PicPath As String = Application.StartupPath & "\Student Picture
If Not My.Computer.FileSystem.DirectoryExists(PicPath) Then
My.Computer.FileSystem.CreateDirectory(PicPath)
End If
PicPath &= "\Student-" & textbox_Search.Text & ".jpg""
Small edit- I realised you wanted to include file name as well. Please do not use "+" when concatenating strings, the proper operator is "&" use the "+" operator only when youre doing math and some other unique cases, such as datatable expression column concatenation.
Currently I have a file name stored in string called filename. The file stored in the string is currently open. Issue is, this file could some times be opened in another instance of Visio.
I want to activate the file that is stored in filename string
My current method does not capture this - The code below only checks if the filename exists among the current/one instance of Visio.
For Each objDoc In objVisio.Documents
If objDoc.Name = filename Then
objDoc.activate
Exit for
End If
Next
How can I activate this file to bring it forward?
windows(filename & " - Microsoft Visio").activate
is not working either
I've tried
Dim objVisio as Visio.Application
Set objVisio = GetObject(filename).Application
which isn't working (maybe due to filename string only having the file name and not the entire file path as well)
Any other brute force methods available out there?
Any help is appreciated!
Try something like this:
objVisio.Application.Caption
Or
AppActivate "Microsoft Visio"
I guess another option is to look into this: https://msdn.microsoft.com/en-us/library/office/ff766749.aspx
I haven't worked extensively with Visio in VBA, so I am interested to see the true answer here.
I am using VBA to create folders automatically. One of the folder names that I need to create contains the character č (c with caron). When I use MkDir in VBA the folder is created with a "c" instead of a "č".
Sample code:
root_folder = "C:\customers\"
folder_name = "háček" 'I do not think you can enter this into the VBA editor, but I am getting the folder_name from an external source
full_folder_path = root_folder & folder_name & "\"
MkDir full_folder_path
attachment.SaveAs full_folder_path & attachment.filename
This will create a folder called "C:\customers\hacek\" instead of "C:\customers\háček\", which then causes the save operation to fail, because it tries to save in "C:\customers\háček\, which of course does not exist. VBA seems to be able to read and handle the characters correctly, because I can read it from my data source and save it to a text file without issues. The problem just seems to exist when it comes to creating folders.
Is there a way to make VBA create the folder with the name that I have actually specified?
edit: formatting
If you use FileSystemObject, you are able to create the Folder with the proper name:
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CreateFolder "C:\customers\hac" & ChrW(269) & "ek" 'ChrW(269) prints č
I am using the following VB Script in a Word 2010 Doc saved as a Microsoft Word Macro-Enabled Template that is protected for form fields:
Sub SaveWithBkMarkedText()
'This code saves the Word file using the bookmark value for Maintenance Memo.
'The file is also saved to a folder in KnowHow for files related to this template.
Dim FileName As String
FileName = ActiveDocument.Bookmarks("mmn").Range.Text
'Use the C:\ code when saving the file locally
ActiveDocument.SaveAs "C:\Download\TemplatesFolders\" & FileName & ".doc"
MsgBox "Your Draft has been saved to KnowHow's Release Documentation site." & _
&vbCrLf & "The file name uses the MM that you included earlier: " & FileName, _
vbInformation + vbOKOnly, "Draft Saved to Minerva"
End Sub
The value entered into the Form Field for a FORMTEXT legacy-form object uses the Bookmark as the file name. Example, if the user enters 12345 as the value, the file is saved using this value as the filename: 12345.doc. This worked fine until a week ago when the filename is now being Prefixed with FORMTEXT 12345.doc. I have tried using this same VB script in older versions of Word on a different machine, and created from a NEW Template with the script added in from scratch, and the same issue is appearing on that machine as well. Prior to this, I was able to update my template with NO problem, but now I can't update this one FORMTEXT field without it affecting the whole file. I can update any other FORMTEXT in the template that does not use the Bookmark value as the file name, and it works. Also, I have tried changing the Bookmark Reference to another FORMTEXT object, as well as saving the file as a .DOCX and the same problem occurs regardless. What is causing the FORMTEXT to appear in the filename?
You have to un-protect the document (template) and then make the VBA programming. Once it is done, then you can protect it again (for filling forms) and you will not see the "FORMTEXT" in the filename when you run the macro.
Hope it helps.
To the OP, did you resolve this issue? I'm now having the same problem, I'm using form field text with bookmarks and using VB.net to get the bookmark.text which is now prefixed with FORMTEXT, just using a bookmark on it own and its OK, no prefix. I'm going to try and remove the first 9 characters from the result using code, a workaround, yes but it might work.
Know this is an old thread but ran into same issue. As a workaround...
Replace FORMTEXT with null "". In OP circumstance:
Dim FileName As String
FileName = ActiveDocument.Bookmarks("mmn").Range.Text
FileName = Replace(FileName, "FORMTEXT ", "")
Not a "fix" for the issue or elegant but it works.
Had the same issue. Simply delete current bookmark and add a new one. If that does not work than instead of using the following:
FileName = ActiveDocument.Bookmarks("mmn").Range.Text
try using:
Selection.GoTo What:=wdGoToBookmark, Name:="mmn"
Filename = Selection.Text