Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 234
Default Copy file and closing original

Hi,

Excel 2000

I'm using VBA to open a text file, this file opens fine but I want to avoid
anyone choosing save or save as and the original text file being over
written. I think I need to open the file and change the property to Read
Only if this is possible.

One way I thought of getting over the issue was to copy the newly opened
file, this new file is then named BOOKn.xls (where n is a number). I would
then close the original text file without saving. I have used VBA to
capture the name and full path of the original text file in a variable named
myFileName and tried using Kill myFileName to close the file, alas this
doesn't work. Also, I'm somewhat lost as to how I copy a whole workbook.

Thanks, Rob


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Copy file and closing original

Just use this when you open:

Workbooks.Open FileName:=xFile, ReadOnly:=True

and I use this when I close:

Workbooks(Fname).Close SaveChanges:=False

This will prevent any changes from being made.

-- Rev


"Rob" wrote in message
...
Hi,

Excel 2000

I'm using VBA to open a text file, this file opens fine but I want to

avoid
anyone choosing save or save as and the original text file being over
written. I think I need to open the file and change the property to Read
Only if this is possible.

One way I thought of getting over the issue was to copy the newly opened
file, this new file is then named BOOKn.xls (where n is a number). I

would
then close the original text file without saving. I have used VBA to
capture the name and full path of the original text file in a variable

named
myFileName and tried using Kill myFileName to close the file, alas this
doesn't work. Also, I'm somewhat lost as to how I copy a whole workbook.

Thanks, Rob




  #3   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 234
Default Copy file and closing original

Rev,

I'm using Workbooks.OpenText filename: = myFileName but the option to add
Read Only for a text file doesn't seem to be there.


"Revolvr" wrote in message
news:%HTmc.17045$k24.8768@fed1read01...
Just use this when you open:

Workbooks.Open FileName:=xFile, ReadOnly:=True

and I use this when I close:

Workbooks(Fname).Close SaveChanges:=False

This will prevent any changes from being made.

-- Rev


"Rob" wrote in message
...
Hi,

Excel 2000

I'm using VBA to open a text file, this file opens fine but I want to

avoid
anyone choosing save or save as and the original text file being over
written. I think I need to open the file and change the property to

Read
Only if this is possible.

One way I thought of getting over the issue was to copy the newly opened
file, this new file is then named BOOKn.xls (where n is a number). I

would
then close the original text file without saving. I have used VBA to
capture the name and full path of the original text file in a variable

named
myFileName and tried using Kill myFileName to close the file, alas this
doesn't work. Also, I'm somewhat lost as to how I copy a whole

workbook.

Thanks, Rob






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Copy file and closing original

You could change the file to readonly after you open it. Or just move the
worksheet to a new (or existing) workbook.

Option Explicit
Sub testme1()

Dim wkbk As Workbook
Dim wks As Worksheet

Workbooks.OpenText Filename:="..."

Set wkbk = ActiveWorkbook
ActiveSheet.Copy
Set wks = ActiveSheet
wkbk.Close SaveChanges:=False

End Sub

Sub testme2()

Dim wkbk As Workbook
Dim wks As Worksheet

Workbooks.OpenText Filename:="..."

Set wkbk = ActiveWorkbook
wkbk.ChangeFileAccess Mode:=xlReadOnly

End Sub

Rob wrote:

Hi,

Excel 2000

I'm using VBA to open a text file, this file opens fine but I want to avoid
anyone choosing save or save as and the original text file being over
written. I think I need to open the file and change the property to Read
Only if this is possible.

One way I thought of getting over the issue was to copy the newly opened
file, this new file is then named BOOKn.xls (where n is a number). I would
then close the original text file without saving. I have used VBA to
capture the name and full path of the original text file in a variable named
myFileName and tried using Kill myFileName to close the file, alas this
doesn't work. Also, I'm somewhat lost as to how I copy a whole workbook.

Thanks, Rob


--

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
copy 1 document and when original updated copy is also JaneAsh Excel Discussion (Misc queries) 4 September 15th 09 04:56 PM
How to tell number of spaces between values in saved text file fromthe original xls file [email protected] Excel Discussion (Misc queries) 1 January 15th 08 11:52 AM
I copy a formula and the results copy from the original cell brooklynsd Excel Discussion (Misc queries) 1 June 23rd 07 01:35 AM
auto save excel file every 10 minutes to its original file name MEG Excel Discussion (Misc queries) 3 September 8th 05 07:12 PM
Auto save replaced my original file and now I need the original? Hols Excel Discussion (Misc queries) 1 August 15th 05 10:34 PM


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