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!

Problems with CommonDialog codes(Open Dialog,precisely)

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
 
As you're playing with Excel VBA, take a look at the GetOpenFilename method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hello PH,

Thanks for your answer.You have lost me slightly there.Have no clue how to use this. Not very conversant with the open dialog codes
Could you enlighten me further,

Thanks'

romij29.
 
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
 
Hello PH,

Thanks for your advice again
Unfortunately,I am working off my jobs 'system and I do not have help files installed soI 'd appreciate any immediate help as I need to sort this out A.S.A.P.
Thanks,

romij29
 
Repair your office install, taking care installing the VBA help file ASAP.
 
PHV,
Its beyond my reach to have those files installed.Office policy.Don't ask me. I need to sort this out now and I am afraid I will not have the time to be chasing some IT person, so if you can give me some concrete answers it'll be appreciated.
Thanks,
 
Hi romij29,

We certainly do post code, sometimes quite a bit, or at least some of us do, but...Tek-Tips is not a HelpDesk. You have obviously started to try and write code, and that is to be encouraged. Where did you get enough information to start if you not have Help? You nust have got something from somewhere to be able to toss out some of the code you posted. So that must be a resource.

However, bottom line is - you will not be able to improve, to truly get your feet wet (so to speak), unless you have Help installed. It is absolutely needed, because yes, we will help with specifics, and some times post some pretty solid code, but YOU have to do most of the work.

For example:
given that I don't seem to find VBA on my system{/quote]
How are you writing the code you posted if you can't find VBA? That does not make sense, unless you are in fact talking about using VB - not VBA - in which case, you need Help even more.

Good luck!

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top