I've been tackling this problem for about 4 hours now and I'm running out of ideas. I've tried a lot of things and Googled aplenty, but certain things, like Common Dialog won't run on this computer. What I'm trying to do is simply open a file browser (preferably only for .ipj files) in Inventor VBA Editor. I will also attach a picture of Form1 to explain what it is I'm doing. It needs to access our K:\\ drive and U:\\ drive as well as the C:\\ drive.
Once the file is selected it is going to display in TextBox1 and the user will be able to prompt the next step of the process.
The closest I have (that works) is a folder browser, shown below.
Private Sub Browse_Click()
Dim pathSelected As String 'This needs to be edited to find files, not just folders...alternatively, add .ipj to end of selected path?
Dim ShellApp As Object
Set ShellApp = CreateObject("Shell.Application"). _
BrowseforFolder(0, "Choose Folder", 0, OpenAt)
pathSelected = ShellApp.self.Path
Me.TextBox1.Text = pathSelected
Set ShellApp = Nothing
End Sub
Any ideas are greatly appreciated and welcomed!!
Thanks,
Alyssa
Solved! Go to Solution.
Solved by pball. Go to Solution.
I ended up needing it again for something else later on in my program and used this. It allowed me to browse a file from a path previously defined by the user and input it in to a textbox in Form3....now I need to make the open button work! Step by step....almost to the hard part of this project. Thank you for your help.
Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Public Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Function SelectFileOpenDialog()
Dim strTemp, strTemp1, pathStr As String
Dim i, n, j As Long
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
Dim Fname As String
OpenFile.lStructSize = Len(OpenFile)
sFilter = "Assembly Files (*.iam)" & Chr(0) & "*.IAM" & Chr(0)
OpenFile.lpstrFilter = sFilter
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = String(257, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
OpenFile.lpstrInitialDir = dir_path
OpenFile.lpstrTitle = "Select An Assembly"
OpenFile.flags = 0
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
MsgBox "No file selected. Please try again."
Else
Fname = Trim$(OpenFile.lpstrFileTitle) ' copy the filename to "Fname"
n = FileLen(OpenFile.lpstrFile) 'length of the file
Resolve.FileName.Text = Fname
End If
End Function
Can't find what you're looking for? Ask the community or share your knowledge.