Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default close a file ater opening with GetOpenFileName

Hi

I open a file with code using GetOpenFileName then copy a sheet to an
already open file.
I have tried altering the code to close the file after the sheet has been
copied but have had no success.

Could someone tell me how to do it?

Many Thanks

Kenny
XP Pro
Office 2003

The code I am currently using is below

Sub OpenAFile()

' thanks MrExcel.com



Dim vFilename As Variant



vFilename = Application.GetOpenFilename("Microsoft Excel
Workbooks,*.xls")



If vFilename = False Then Exit Sub 'User pressed Cancel



Workbooks.Open vFilename




Sheets("Data").Select



Sheets("Data").Copy Befo=Workbooks( _

"Copy of Defects Audit V4.01getopenfilename.xls").Sheets(1)






MyAudit



Sheets("Data").Delete

Sheets("Report").Select

End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default close a file ater opening with GetOpenFileName

See this tester

I use
Set wb = Workbooks.Open(FName)

Now you can use this after you do the copy
wb.Close False


Sub test()
Dim FName As Variant
Dim wb As Workbook
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = CurDir

MyPath = ThisWorkbook.Path
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls")
If FName < False Then
Set wb = Workbooks.Open(FName)

' do your stuff

wb.Close False
End If

ChDrive SaveDriveDir
ChDir SaveDriveDir

End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Forum Freak" wrote in message ...
Hi

I open a file with code using GetOpenFileName then copy a sheet to an
already open file.
I have tried altering the code to close the file after the sheet has been
copied but have had no success.

Could someone tell me how to do it?

Many Thanks

Kenny
XP Pro
Office 2003

The code I am currently using is below

Sub OpenAFile()

' thanks MrExcel.com



Dim vFilename As Variant



vFilename = Application.GetOpenFilename("Microsoft Excel
Workbooks,*.xls")



If vFilename = False Then Exit Sub 'User pressed Cancel



Workbooks.Open vFilename




Sheets("Data").Select



Sheets("Data").Copy Befo=Workbooks( _

"Copy of Defects Audit V4.01getopenfilename.xls").Sheets(1)






MyAudit



Sheets("Data").Delete

Sheets("Report").Select

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default close a file ater opening with GetOpenFileName

Many thanks Ron. You have come to my rescue yet again. It worked a treat.
As usual I will credit you and your website in the macro for future
reference.

Regards
Kenny


"Ron de Bruin" wrote in message
...
See this tester

I use
Set wb = Workbooks.Open(FName)

Now you can use this after you do the copy
wb.Close False


Sub test()
Dim FName As Variant
Dim wb As Workbook
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = CurDir

MyPath = ThisWorkbook.Path
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls")
If FName < False Then
Set wb = Workbooks.Open(FName)
' do your stuff
wb.Close False
End If

ChDrive SaveDriveDir
ChDir SaveDriveDir

End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Forum Freak" wrote in message
...
Hi

I open a file with code using GetOpenFileName then copy a sheet to an
already open file.
I have tried altering the code to close the file after the sheet has been
copied but have had no success.

Could someone tell me how to do it?

Many Thanks

Kenny
XP Pro
Office 2003

The code I am currently using is below

Sub OpenAFile()

' thanks MrExcel.com



Dim vFilename As Variant



vFilename = Application.GetOpenFilename("Microsoft Excel
Workbooks,*.xls")



If vFilename = False Then Exit Sub 'User pressed Cancel



Workbooks.Open vFilename




Sheets("Data").Select



Sheets("Data").Copy Befo=Workbooks( _

"Copy of Defects Audit V4.01getopenfilename.xls").Sheets(1)






MyAudit



Sheets("Data").Delete

Sheets("Report").Select

End Sub



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
GetOpenFileName to select a .URL file Gary''s Student Excel Programming 10 April 22nd 08 08:37 PM
GetOpenFilename Close Karen53 Excel Programming 2 March 16th 08 06:22 AM
Opening a document captured by Application.GetOpenFilename with hyperlink [email protected] Excel Programming 2 May 16th 07 05:18 PM
Using FileDialog or GetOpenFileName To Allow File Creation WhyIsDoug Excel Programming 1 July 28th 05 05:14 PM
Select file after GetOpenFilename RB Smissaert Excel Programming 1 February 5th 05 04:15 PM


All times are GMT +1. The time now is 07:15 AM.

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"