Hi,
I've been building some macros via the VBA editor available in InfoConnect Desktop, and would like to be able to invoke/use Microsoft's "FIleDialog" control (documented here: https://docs.microsoft.com/en-us/office/vba/api/Office.FileDialog) to prompt the user for a file. The macro(s) I'm working on run froim Common module(s) in the InfoConnect VBA editor. So far I haven't been able to get that to work. Anyone have any tips?
Thanks
#Reflection#Vba#FileDialogObject#macroeditor#OfficeHi,
As a start, you could follow the instructions in this HowTo document. This is like a tutorial and after you have successfully completed it, you should be able to adapt it to your own Host (mainframe or AS400) environment.
https://www.microfocus.com/documentation/reflection-desktop/17-1/vba-guide/get-data-from-spreadsheet.html
Hi,
I've been building some macros via the VBA editor available in InfoConnect Desktop, and would like to be able to invoke/use Microsoft's "FIleDialog" control (documented here: https://docs.microsoft.com/en-us/office/vba/api/Office.FileDialog) to prompt the user for a file. The macro(s) I'm working on run froim Common module(s) in the InfoConnect VBA editor. So far I haven't been able to get that to work. Anyone have any tips?
Thanks
#Reflection#Vba#FileDialogObject#macroeditor#OfficeHi Rob,
if you are using 64 bit office ou will not be able to use it's FileDialog.
Personally, I would just run with the Microsoft 32-bit common dialog.
here is some sample code:
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private 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
Function GetFileName() As String
Dim Filename As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
Filename.lStructSize = Len(Filename)
Filename.hwndOwner = &H0
sFilter = "All Files (*.*)" & Chr(0) & "*.*" & Chr(0) & _
"Text Files (*.txt)" & Chr(0) & "*.txt" & Chr(0) & _
"ABC Files (*.abc)" & Chr(0) & "*.abc" & Chr(0)
Filename.lpstrFilter = sFilter
Filename.nFilterIndex = 1
Filename.lpstrFile = String(257, 0)
Filename.nMaxFile = Len(Filename.lpstrFile) - 1
Filename.lpstrFileTitle = Filename.lpstrFile
Filename.nMaxFileTitle = Filename.nMaxFile
Filename.lpstrInitialDir = Environ$("USERPROFILE") & "\\Documents"
Filename.lpstrTitle = "Open"
Filename.flags = 0
lReturn = GetOpenFileName(Filename)
If lReturn = 0 Then
MsgBox "No file selected"
Else
GetFileName = Trim(Left(Filename.lpstrFile, InStr(1, OpenFile.lpstrFile, &H0) - 1))
End If
End Function
Sub Test()
Dim MyFileName As String
MyFileName = GetFileName
If Len(MyFileName) > 0 Then
MsgBox MyFileName
End If
End Sub
Tom