Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

CATVBA Save issue when Periods are in filename

Status
Not open for further replies.

Pspboy17

Mechanical
Mar 25, 2024
2
Hello everyone,

This is my first thread on here, I'm having some issues with a seemingly simple part of a macro I'm working on.
Just as a bit of background, I'm modifying an existing internal macro that replaces certain segments of our part/product names to reflect a new code for that design. I'm having a problem getting CatVBA to save parts properly when they have a period in the filename. It just saves them as "files" with no extension, going to assume it's getting confused and interpreting the period as the extension.

For instance we might have
12345__0001.0001__Description.catpart
and after I run it through my macro it turns into
54321__0001.0001__Description

With no file extension. I'm not sure how to go about correcting this, and I might just be very confused and going down the wrong road. I found this thread with a macro to know the filetype but I would need some assistance "piping" it into a block of code like below which saves as a particular filetype (not entirely sure where I got this from currently, might have been from this forum). Even then I don't know if it will save correctly.
I've also tried temporarily replacing the period with another character, but I'm confused on how to replace the period back into the filename once it's saved. Any help would be greatly appreciated.


Code:
 Select Case "placeholder"
                Case "Part"
					
                    StoreDoc.Parent.SaveAs newPath, catFileTypeCATPart
                Case "Assembly Structure"
					 
                    StoreDoc.Parent.SaveAs newPath, catFileTypeCATProduct
                Case "Drawing"
                    StoreDoc.Parent.SaveAs newPath, catFileTypeCATDrawing
                Case Else                 
					 
                    Instance.ReferenceProductParent.SaveAs newPath
            End Select

If I'm on the wrong track, is there anyway to get normal save behavior from this command with these part names?

Code:
Instance.ReferenceProduct.Parent.SaveAs

Otherwise I could maybe see "SaveAs partnumber & path & extension" working with the code above, but that seems pretty messy and roundabout.
 
Replies continue below

Recommended for you

Just incase someone has a similar issue in the future I ended up extracting the extension from the instance name, and then adding the extension onto partnumbers with periods in the name when saving. It's kinda messy but It seems to work fine.

Code:
					Dim GetExtension as String
GetExtension = Mid(Instance.ReferenceProduct.Parent.Name, InStrRev(Instance.ReferenceProduct.Parent.Name, ".") + 1)

If InStr(PartNumber, ".") = 0 Then
	Instance.ReferenceProduct.Parent.SaveAs newPath
	Else
	Instance.ReferenceProduct.Parent.SaveAs newPath & "." & GetExtension
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor