Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

File Browser in VBA Editor

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
alyssaweaver
4903 Views, 4 Replies

File Browser in VBA Editor

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.

 

 

Form1.JPG

 

 

 

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

 

Best Wishes,
Ali

|---------------------------------------------------------------------------------------------------------------------|
"It's a screwdriver, not a water pistol! What are you gonna do? Construct a cabinet at them?!"
4 REPLIES 4
Message 2 of 5
alyssaweaver
in reply to: alyssaweaver

Side note, I'm new to this. I learned Visual Basic....on Friday. So I have quite a lot to learn.
Best Wishes,
Ali

|---------------------------------------------------------------------------------------------------------------------|
"It's a screwdriver, not a water pistol! What are you gonna do? Construct a cabinet at them?!"
Message 3 of 5
alyssaweaver
in reply to: alyssaweaver

I have not found a solution, but circumvented the process instead and no longer require help.

Best Wishes,
Ali

|---------------------------------------------------------------------------------------------------------------------|
"It's a screwdriver, not a water pistol! What are you gonna do? Construct a cabinet at them?!"
Message 4 of 5
pball
in reply to: alyssaweaver

I found some code to do an open file dialog. You can find it in the thread I'm linking to.

http://forums.autodesk.com/t5/Inventor-Customization/Inventor-2013-FileDialog-that-does-not-point-to...
Message 5 of 5
alyssaweaver
in reply to: pball

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

Best Wishes,
Ali

|---------------------------------------------------------------------------------------------------------------------|
"It's a screwdriver, not a water pistol! What are you gonna do? Construct a cabinet at them?!"

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums