Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 4
Default error on a macro

I have created this macro to open an excel file; but if a file is not selected
than end up in error, is there a way to stop the macro without an error
this is what i have

Sub OpenWorkbok()
Dim fName As String
fName = Application.GetOpenFilename()
Workbooks.Open Filename:=fName
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 2,480
Default error on a macro

Hi

Sub OpenWorkbok()
Dim fName As String
fName = Application.GetOpenFilename()
If fname < "" Then
Workbooks.Open Filename:=fName
End If
End Sub


--
Regards
Roger Govier

"Exceldude" wrote in message
...
I have created this macro to open an excel file; but if a file is not
selected
than end up in error, is there a way to stop the macro without an error
this is what i have

Sub OpenWorkbok()
Dim fName As String
fName = Application.GetOpenFilename()
Workbooks.Open Filename:=fName
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 35,218
Default error on a macro

Option Explicit
Sub OpenWorkbok()
Dim fName As Variant 'could be the boolean false
fName = Application.GetOpenFilename
if fname = false then
'user hit cancel
else
workbooks.Open Filename:=fName
end if
End Sub

Exceldude wrote:

I have created this macro to open an excel file; but if a file is not selected
than end up in error, is there a way to stop the macro without an error
this is what i have

Sub OpenWorkbok()
Dim fName As String
fName = Application.GetOpenFilename()
Workbooks.Open Filename:=fName
End Sub


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 4
Default error on a macro

Thank you Dave,
that was exactly what I needed; it works Great


"Dave Peterson" wrote:

Option Explicit
Sub OpenWorkbok()
Dim fName As Variant 'could be the boolean false
fName = Application.GetOpenFilename
if fname = false then
'user hit cancel
else
workbooks.Open Filename:=fName
end if
End Sub

Exceldude wrote:

I have created this macro to open an excel file; but if a file is not selected
than end up in error, is there a way to stop the macro without an error
this is what i have

Sub OpenWorkbok()
Dim fName As String
fName = Application.GetOpenFilename()
Workbooks.Open Filename:=fName
End Sub


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Worksheet Functions 1 May 3rd 08 02:35 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Discussion (Misc queries) 1 May 3rd 08 10:52 AM
Macro error please help Francesco Excel Discussion (Misc queries) 1 April 12th 06 10:05 AM
Macro error : Application-defined or object-defined error Joe Excel Discussion (Misc queries) 3 January 27th 06 02:32 PM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM


All times are GMT +1. The time now is 03:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"