Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Open Dialog Problems

Status
Not open for further replies.

romij29

Technical User
Nov 23, 2004
49
GB
Hello Everyone,

I am writing a program whereby I will be able to click on a form button I have designed and have an open dialog box open,whereby I choose a file and basically have contents within that file copied into another file.I would prefer themacro to do it automatically.However,I am not very familiar with open dialog programming and when i write the ffs codes (below),The second bit gives me get the message
RunTime Error 91:"Object variable or With block variable not set."
First code :
Private Sub Workbook_Open()
Call mnuFileOpen_Click

Trad_Accs.Show vbModeless
End Sub


Second Code:

Sub mnuFileOpen_Click()
Dim WhatFile As String
Dim CommonDialog1 As Dialog
CommonDialog1.Filter = "Excel Files (*.xls)|*.xls|Text Files (*.txt)|*.txt"
CommonDialog1.FilterIndex = 2
CommonDialog1.ShowOpen
WhatFile = CommonDialog1.Filename

Iget the error on the second code line4.

Also, I need to display only excel files.
How do I do this??

Secondly,
I can seem to get the
Projects --Components tab in the menu
as i am only able to enter VBA through my worksheet..Is there anyway I can do the CommonDialog program without the icon itself. If not ,how do I get it given that I don't seem to find VBA on my system,and also I need to put the code within my worksheet..
Any assistance will be greatly appreciated
Thanks,

Regards,

romij29
 
My english isn't that good but if you're trying to select a file take a look at GetOpenFilename rather then the commondialog.

grtz Flippertje
 
I get it:))

application.getopenfilename ("Text Files (*.txt), *.txt,1,"Titlename of the window",,false)

(filefilter, filterindex, title, buttontext, multiselect)

have fun
 
Thanks Flippertje,
I am new to this so it would be good idea if you could explain in laymans terms what this is all about.What is the parentheses like for the items .And could you write it in perfect syntax pls.

Regards
 
When in VBE (Alt+F11) launch the Object browser (F2), search it for getopenfilename and press the F1 key when found.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
As I explained before,I use this at work and don't have help files installed due to administrator restrictions. Don't ask me why,but its not allowed for some reason.
Hence my blindness.
Put the ff code in my program and when I step thru it ,there is nothing.Any ideas,concrete pls??


Sub mnuFileOpen_Click()

Application.GetOpenFilename [(All Files (*.*)|*.*|Excel Files (*.xls)|*.xls), 2, (Dialog Box Open), (Form) , (False)]

End Sub
 
i have a get open file code that I have no clue about.whether the actual file names shd be included.Is that right.I can seem to distinguish between the instructions and code itself.
For eg, from code

ZeroMemory = "ofn", sizeof(ofn)
ofn.lpStrFile = szfile
ofn.nMaxFile = sizeof(szfile)
How do I get this file sizes if I need to put that in place of size of file..
Also do I have to put in the actual file path in place of szfile at the lpstrFile line.
Also what does ofn.lpStrFile [0] = "'\0'" mean??
The whole code actually.what does it mean??Understand what it does,initialization and all that...

Any assistance would be greatly appreciated.And one more thing,i have no access to vb help files.work IT administration.Don't ask..
Thanks

Sub Button1_Click()

OPENFILENAME
char szfile
hwnd hwnd
Handle hf


ZeroMemory = "ofn", sizeof(ofn)

ofn.lStructSize = OPENFILENAME_SIZE_VERSION
ofn.hWndOwner = hwnd
ofn.lpStrFile = szfile
ofn.lpStrFile [0] = "'\0'"
ofn.nMaxFile = sizeof(szfile)
ofn.lpStrFilter = "All Files\*.*\Excel Files\*.XLS"
ofn.lpstrFilterIndex = 2
ofn.lpStrFileTitle = Null
ofn.nMaxFileTitle = 0
ofn.lpStrInitialDir = Null
ofn.Flags = OFN_PATHMUSTEXIST \ OFN_FILEMUSTEXIST


If (GetOpenFilename(ofn) = True) Then
hf = Create(ofn.lpstrfile, GENERIC_READ, 0,(LPSECURITY_ATTRIBUTES) NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL)

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top