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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax question 1

Status
Not open for further replies.
May 2, 2003
175
GB
Hi there, I have just started to learn VB as another string to my bow, and I am just trying to produce macros that are useful to me at the moment, but I am stuck trying to find out bits of syntax.

in this case, I am trying to find out if it is possible to put a line into a macro that will open the "File Open" dialog box. Is this possible within the confines of Excell.

I am running Excell 2000 by the way.

Kind regards
Rob
 
TRY THIS...I GOT THIS CODE FROM THIS SITE, IT WORKS WELL


Sub CustomSaveAs()
Dim FName As String
Dim SuggestedPath As String
Dim FFilter As String
Dim FIndex As Integer

On Error GoTo CustomSaveAs_Error

' Set SuggestedPath to the location you want user to save file and optionally add suggested filename. For this example I made it a local var but could also be global.
SuggestedPath = "C:\SuggestedFilename.xls"
' Set FFilter to desired extension(s), if needed; see Help on GetSaveAsFilename
FFilter = "Microsoft Excel Workbook (*.xls), *.xls"
FIndex = 1 'See Help on GetSaveAsFilename
FName = Application.GetSaveAsFilename(SuggestedPath, FFilter, FIndex, "Save As")
If FName <> &quot;False&quot; Then
' If FName = &quot;False&quot; then user clicked Cancel
Application.EnableEvents = False
ActiveWorkbook.SaveAs FName
End If

CustomSaveAs_Exit:
Application.EnableEvents = True
Exit Sub
CustomSaveAs_Error:
MsgBox &quot;Error &quot; & Err.Number & &quot;, &quot; & Err.Description
Resume CustomSaveAs_Exit

End Sub
 
Thankyou, I shall try this tonight.

Just one quick question, it seems that what is needed is for a bogus filename so that it does default to false to make it happen is that right?

Because I am literally making a macro that saves the work book, closes it, and goes to open new. It is for like data input invoicing type thing.

Well it's a starting point anyway.
 
So do you even need a dialog box for user input?
 
what I was trying to do was just get the file open box to pop up, I hoped it would be just a simple line like:

blahblah.open

where blahblah is the syntax I don't know, and open I can't seem to find either?

Is it possible to open files simply through VBA or will it actually envolve writing something in Visual basic and then applying it?

This is spose to be just a simple macro that is seeming to be quite not possible.
 
do you really need the file open dialogue ???

would

workbooks(&quot;Fullpathandname&quot;).open

not do for you

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
Hi GreenTeeth,

Showing the dialog box does, indeed, just need a single line ..

Code:
Application.Dialogs(xlDialogOpen).Show

Enjoy,
Tony
 
Absolutely Superb TonyJollans, thankyou, That has well achieved my goal. Have a star.

Thanks everyone else for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top