Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default Error message

Hello all, i have the code below which i got from this site and it works
great, just if cancel is selected i get an error and i would then like
to give a message asking if they would really like to cancel, but im not
sure where to put it in, could some body please help ?


Sub GetDLoadFromSapStd()

Dim mySavedPath As String
Dim Cancel As Variant
mySavedPath = CurDir

ChDirNet "\\zadad01\sapinter\ZA-TM-RECON\DOWNLOAD"
fileToOpen = Application _
.GetOpenFilename("Text Files (*.csv),*.csv") mySapFile =
fileToOpen
Workbooks.OpenText FileName:=mySapFile
ChDirNet mySavedPath
OptionCheckStd
End If
End Sub


Les Stout

*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Error message

Try this.

Sub GetDLoadFromSapStd()

Dim mySavedPath As String
' Dim Cancel As Variant ' Dont see where needed
mySavedPath = CurDir

ChDirNet "\\zadad01\sapinter\ZA-TM-RECON\DOWNLOAD"
' ========== Insert from here =======
TryAgain:
fileToOpen = Application.GetOpenFilename("Text Files (*.csv),*.csv")
If fileToOpen = "False" Then
If MsgBox("Do you want to cancel?", vbYesNo) = vbYes Then
ChDirNet mySavedPath
Exit Sub
Else
GoTo TryAgain
End If
End If
' ========== to here =========
mySapFile = fileToOpen
Workbooks.OpenText Filename:=mySapFile
ChDirNet mySavedPath
OptionCheckStd
' End If ' Dont see where needed
End Sub




*** Sent via Developersdex http://www.developersdex.com ***
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Error message

One more way:

Option Explicit
Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long
Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting path."
End Sub

Sub GetDLoadFromSapStd()

Dim mySavedPath As String
Dim FileToOpen As Variant
Dim mySapFile As Variant
Dim Cancel As Variant
mySavedPath = CurDir

On Error Resume Next
ChDirNet "\\zadad01\sapinter\ZA-TM-RECON\DOWNLOAD"
If Err.Number < 0 Then
'what should happen
MsgBox "Please change to your own folder"
Err.Clear
End If

FileToOpen = Application _
.GetOpenFilename("Text Files (*.csv),*.csv")

'one more check
if filetoopen = false then
'user hit cancel
exit sub
end if

mySapFile = FileToOpen
Workbooks.OpenText Filename:=mySapFile
ChDirNet mySavedPath
'OptionCheckStd
'End if
End Sub


Les Stout wrote:

Hello all, i have the code below which i got from this site and it works
great, just if cancel is selected i get an error and i would then like
to give a message asking if they would really like to cancel, but im not
sure where to put it in, could some body please help ?

Sub GetDLoadFromSapStd()

Dim mySavedPath As String
Dim Cancel As Variant
mySavedPath = CurDir

ChDirNet "\\zadad01\sapinter\ZA-TM-RECON\DOWNLOAD"
fileToOpen = Application _
.GetOpenFilename("Text Files (*.csv),*.csv") mySapFile =
fileToOpen
Workbooks.OpenText FileName:=mySapFile
ChDirNet mySavedPath
OptionCheckStd
End If
End Sub

Les Stout

*** Sent via Developersdex http://www.developersdex.com ***


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default Error message

Thanks Edward and Dave for your input.

best regards,

Les Stout

*** Sent via Developersdex http://www.developersdex.com ***
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
error message: compile error, argument not optional Pierre via OfficeKB.com Excel Programming 3 September 5th 05 03:45 PM
VBA Error Message "Compile Error...." Steve Excel Discussion (Misc queries) 3 July 15th 05 09:20 AM
Excel XP error message Run Time Error 91 Lenny[_3_] Excel Programming 1 March 3rd 05 10:15 PM
changing the message in an error message The Villages DA Excel Worksheet Functions 2 February 18th 05 05:30 PM
How do I get rid of "Compile error in hidden module" error message David Excel Discussion (Misc queries) 4 January 21st 05 11:39 PM


All times are GMT +1. The time now is 05:44 AM.

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

About Us

"It's about Microsoft Excel"