Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Open window - on error

Sub Opendefactivewkbk()
On Error GoTo ErrorTrap1
ChDrive ActiveWorkbook.Path
ChDir ActiveWorkbook.Path
FName = Application.GetOpenFilename()
ErrorTrap1:
ChDrive "D"
FName = Application.GetOpenFilename()
If FName < False Then Workbooks.Open FName

End Sub

The above macro works well without the on error - however i need it in
case i want to open a file from an active workbook which has not yet
been saved.
My problem is that I have 2 open window appearing one after the other
if there is no error.
an anybody correct my code pls
thxs

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Open window - on error

Hi AL007,

Try:

'=============
Sub Opendefactivewkbk()
Dim FName

If ActiveWorkbook.Path < vbNullString Then
ChDrive ActiveWorkbook.Path
ChDir ActiveWorkbook.Path
Else
ChDrive "D"
End If

FName = Application.GetOpenFilename()
If FName < False Then Workbooks.Open FName

End Sub
'<<=============


---
Regards,
Norman


"al007" wrote in message
oups.com...
Sub Opendefactivewkbk()
On Error GoTo ErrorTrap1
ChDrive ActiveWorkbook.Path
ChDir ActiveWorkbook.Path
FName = Application.GetOpenFilename()
ErrorTrap1:
ChDrive "D"
FName = Application.GetOpenFilename()
If FName < False Then Workbooks.Open FName

End Sub

The above macro works well without the on error - however i need it in
case i want to open a file from an active workbook which has not yet
been saved.
My problem is that I have 2 open window appearing one after the other
if there is no error.
an anybody correct my code pls
thxs



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Open window - on error

perfect!! - thxs

Norman Jones wrote:
Hi Al007,

Try:

'=============
Sub Opendefactivewkbk()
Dim wb As Workbook
Dim FName
Dim myDir As String

myDir = CurDir

On Error Resume Next
Set wb = ActiveWorkbook
On Error GoTo 0

If Not wb Is Nothing Then
If ActiveWorkbook.Path < vbNullString Then
ChDrive ActiveWorkbook.Path
ChDir ActiveWorkbook.Path
End If
Else
ChDrive "D" '<<==== CHANGE
ChDir "D:\Test" '<<==== CHANGE

End If

FName = Application.GetOpenFilename()
If FName < False Then Workbooks.Open FName

ChDrive myDir
ChDir myDir

End Sub
'<<=============

---
Regards,
Norman


"al007" wrote in message
oups.com...
Norman,
sorry to trouble u, but have tested the code & it does not work -
it's not opening folder of my current active workbook (but my last
opened folder) & it does not work if I apply it when I have no active
workbook open - can u help pls
thxs


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
How I can I open a small window within window Loz Excel Discussion (Misc queries) 0 May 20th 07 09:04 PM
OPen an DOS WIndow nathandaviesuk Excel Discussion (Misc queries) 1 December 21st 05 12:40 PM
open new window lost in excel Excel Discussion (Misc queries) 2 April 14th 05 11:08 PM
Excel workbook does not open in open window on desktop DeanH Excel Discussion (Misc queries) 2 March 8th 05 09:51 AM
Error on activating a window a open workbook Hari[_3_] Excel Programming 1 June 11th 04 12:58 AM


All times are GMT +1. The time now is 01:47 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"