dnenad Posted Sunday at 01:13 PM Posted Sunday at 01:13 PM This macro works in Solidworks 2024. Would someone please help me to get it working properly for 2025? See attached file. Thanks. jn_2.txt Quote
SLW210 Posted Tuesday at 03:14 PM Posted Tuesday at 03:14 PM What is the error you get? SolidWorks changed a few VBA commands from 2024 to 2025, you'll probably get better results on a SolidWorks/Dassault Systems forum. A quick search on SolidWorks VBA changes between 2024 and 2025 might help. Quote
mhupp Posted Tuesday at 08:17 PM Posted Tuesday at 08:17 PM (edited) You can wrap the inputbox with ucase(trim( or even add things infront like i did with description eliminating lines of code. old ' --- Ask user if they want to Add or Remove description --- action = InputBox("Type 'A' to Add description or 'R' to Remove description:", "Action Choice", "A") action = UCase(Trim(action)) If action <> "A" And action <> "R" Then MsgBox "Invalid input.": Exit Sub ' --- Optional prefix --- prefix = "" Dim userInput As String userInput = InputBox("Enter component location prefix: T for Top, B for Bottom, leave blank for none:", "Prefix Option") userInput = UCase(Trim(userInput)) If userInput = "T" Then prefix = "Top_" If userInput = "B" Then prefix = "Bot_" ' --- Optional description (only if adding) --- If action = "A" Then description = InputBox("Enter description to append (leave blank for none):", "Optional Description") description = Trim(description) If description <> "" Then description = "_" & description If description <> "" Then CopyToClipboardAPI (description) MsgBox "Description '" & description & "' copied to clipboard." End If End If New ' --- Ask user if they want to Add or Remove description --- action = UCase(Trim(InputBox("Type 'A' to Add description or 'R' to Remove description:", "Action Choice", "A"))) If action <> "A" And action <> "R" Then MsgBox "Invalid input.": Exit Sub ' --- Optional prefix --- Dim userInput As String userInput = UCase(Trim(InputBox("Enter component location prefix: T for Top, B for Bottom, leave blank for none:", "Prefix Option"))) Select Case True Case userInput = "T" prefix = "Top_" Case userInput = "B" prefix = "Bot_" Case Else prefix = "" End Select ' --- Optional description (only if adding) --- If action = "A" Then description = "_" & Trim(InputBox("Enter description to append (leave blank for none):", "Optional Description")) If description <> "_" Then ;old code would still allow "_" to be copied to clipboard this skips and should prob exit sub if description is only "_" ? CopyToClipboardAPI (description) MsgBox "Description '" & description & "' copied to clipboard." Else MsgBox "Description is Blank " & vbCrLf & " Exiting Command" Exit Sub End If End If Didn't run past fso. please describe what your running into. Edited Tuesday at 08:20 PM by mhupp Quote
BIGAL Posted Tuesday at 10:52 PM Posted Tuesday at 10:52 PM I only dabble in VBA but have these changed "kernel32" "user32" or maybe where you point to them, have had some VBA do this that refers to wrong library used. Quote
mhupp Posted 23 hours ago Posted 23 hours ago (edited) Also noticed the CopyToClipboardAPI can be replaced with three lines if you add a reference to Microsoft Forms 2.0 Object Library Dim obj As New MSForms.DataObject ... If description <> "_" Then obj.SetText description obj.PutInClipboard MsgBox "Description '" & description & "' copied to clipboard." Else Edited 23 hours ago by mhupp Quote
mhupp Posted 23 hours ago Posted 23 hours ago (edited) 14 hours ago, BIGAL said: I only dabble in VBA but have these changed "kernel32" "user32" or maybe where you point to them, have had some VBA do this that refers to wrong library used. Yea with the resent forced update in windows 11 some things went funky for people. Edited 23 hours ago by mhupp Quote
SLW210 Posted 19 hours ago Posted 19 hours ago From what I quickly look into on the Dassault Systems (SolidWorks) site, among other changes for SolidWorks 2025 API, there was a change in the methods for saving a drawing. My WAG is that's where the VBA is failing on SolidWorks 2025, could be another change as well. 1 Quote
mhupp Posted 15 hours ago Posted 15 hours ago (edited) 4 hours ago, SLW210 said: ... among other changes for SolidWorks 2025 API, there was a change in the methods for saving a drawing. Err now i don't want to update to 2026 have alot of save macros that work alongside PDM. Edited 14 hours ago by mhupp Quote
SLW210 Posted 1 hour ago Posted 1 hour ago I only did a quick peek since I am busy and haven't used SolidWorks in quite a while, but it looked like a pretty easy change. I am sure a deeper dig on the forums would show the process for updating, but I really didn't have time to look harder into it. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.