PC Review


Reply
Thread Tools Rate Thread

copying data into a file with a modify pw & read-only recommended

 
 
=?Utf-8?B?cm9ja2hhbW1lcg==?=
Guest
Posts: n/a
 
      20th Jun 2007
I have a macro in sourceFile which opens a destFile to copy data from
sourceFile into destFile and then tries to save the destFile. My destFile in
this case is one which has a modify password set and also has the open
read-only recommended option set.

What I am experiencing is that even though I enter the password when the
prompt comes up when the destFile is opened and I click "ok" instead of "read
only", the destFile is still opened as read-only.

My question is: Is there a way to modify my code such that the destFile will
NOT be opened read only when the proper password is entered when prompted?
Excerpts of my code below - it all works except that destFile is always
opened read only no matter what and therefore the line that saves the
destFile gives an error.

Thanks a lot.

' this is the file open sub
Sub threed_file_open()
fileOpened = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False
If Not fileSelected Then
MsgBox "No 3D template file selected yet!"
Exit Sub
End If
sourceFile = ActiveWorkbook.Name
Workbooks.Open Filename:=sourceFileName, Notify:=False
fileOpened = True
destFile = ActiveWorkbook.Name
Windows(sourceFile).Activate
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub


' this is the code which does the copying & saving
Windows(sourceFile).Activate
topbot.Activate ' this is the tab in sourceFile I want to copy from
Range(topbotExport1stCell, topbotExportLastCell).Select
Selection.Copy
Windows(destFile).Activate
Worksheets(topbotImportTab).Activate
topbotImportCell.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False
ActiveWorkbook.Save
MsgBox "Changes to " & destFile & " saved."

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      21st Jun 2007
This code (copied from your post) indicates that the destination file is the
same as the source file, same workbook, so I guess I don't understand the
question.

sourceFile = ActiveWorkbook.Name
Workbooks.Open Filename:=sourceFileName, Notify:=False
fileOpened = True
destFile = ActiveWorkbook.Name

Is it the worksheet that is protected within the workbook?


"rockhammer" wrote:

> I have a macro in sourceFile which opens a destFile to copy data from
> sourceFile into destFile and then tries to save the destFile. My destFile in
> this case is one which has a modify password set and also has the open
> read-only recommended option set.
>
> What I am experiencing is that even though I enter the password when the
> prompt comes up when the destFile is opened and I click "ok" instead of "read
> only", the destFile is still opened as read-only.
>
> My question is: Is there a way to modify my code such that the destFile will
> NOT be opened read only when the proper password is entered when prompted?
> Excerpts of my code below - it all works except that destFile is always
> opened read only no matter what and therefore the line that saves the
> destFile gives an error.
>
> Thanks a lot.
>
> ' this is the file open sub
> Sub threed_file_open()
> fileOpened = False
> Application.DisplayAlerts = False
> Application.ScreenUpdating = False
> If Not fileSelected Then
> MsgBox "No 3D template file selected yet!"
> Exit Sub
> End If
> sourceFile = ActiveWorkbook.Name
> Workbooks.Open Filename:=sourceFileName, Notify:=False
> fileOpened = True
> destFile = ActiveWorkbook.Name
> Windows(sourceFile).Activate
> Application.DisplayAlerts = True
> Application.ScreenUpdating = True
> End Sub
>
>
> ' this is the code which does the copying & saving
> Windows(sourceFile).Activate
> topbot.Activate ' this is the tab in sourceFile I want to copy from
> Range(topbotExport1stCell, topbotExportLastCell).Select
> Selection.Copy
> Windows(destFile).Activate
> Worksheets(topbotImportTab).Activate
> topbotImportCell.Select
> Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks:=False, Transpose:=False
> ActiveWorkbook.Save
> MsgBox "Changes to " & destFile & " saved."
>

 
Reply With Quote
 
=?Utf-8?B?cm9ja2hhbW1lcg==?=
Guest
Posts: n/a
 
      21st Jun 2007
Once the workbooks.open line executes, the activeworkbook becomes the opened
workbook so sourceFile <> destFile.

The destFile has a modify password set and also the open-read-only option
set via File->Save As->Options->General, etc.

What I am experiencing is that when destFile is opened via the vb code I
have, the normal popup that prompts for the password shows up. However,
unlike when I open destFile via File->Open, even if I entered the correct
password and click "ok" (not "read only"), destFile is still opened as
read-only. Therefore the line that saves the file generates a run-time error.

Thanks.


"JLGWhiz" wrote:

> This code (copied from your post) indicates that the destination file is the
> same as the source file, same workbook, so I guess I don't understand the
> question.
>
> sourceFile = ActiveWorkbook.Name
> Workbooks.Open Filename:=sourceFileName, Notify:=False
> fileOpened = True
> destFile = ActiveWorkbook.Name
>
> Is it the worksheet that is protected within the workbook?
>
>
> "rockhammer" wrote:
>
> > I have a macro in sourceFile which opens a destFile to copy data from
> > sourceFile into destFile and then tries to save the destFile. My destFile in
> > this case is one which has a modify password set and also has the open
> > read-only recommended option set.
> >
> > What I am experiencing is that even though I enter the password when the
> > prompt comes up when the destFile is opened and I click "ok" instead of "read
> > only", the destFile is still opened as read-only.
> >
> > My question is: Is there a way to modify my code such that the destFile will
> > NOT be opened read only when the proper password is entered when prompted?
> > Excerpts of my code below - it all works except that destFile is always
> > opened read only no matter what and therefore the line that saves the
> > destFile gives an error.
> >
> > Thanks a lot.
> >
> > ' this is the file open sub
> > Sub threed_file_open()
> > fileOpened = False
> > Application.DisplayAlerts = False
> > Application.ScreenUpdating = False
> > If Not fileSelected Then
> > MsgBox "No 3D template file selected yet!"
> > Exit Sub
> > End If
> > sourceFile = ActiveWorkbook.Name
> > Workbooks.Open Filename:=sourceFileName, Notify:=False
> > fileOpened = True
> > destFile = ActiveWorkbook.Name
> > Windows(sourceFile).Activate
> > Application.DisplayAlerts = True
> > Application.ScreenUpdating = True
> > End Sub
> >
> >
> > ' this is the code which does the copying & saving
> > Windows(sourceFile).Activate
> > topbot.Activate ' this is the tab in sourceFile I want to copy from
> > Range(topbotExport1stCell, topbotExportLastCell).Select
> > Selection.Copy
> > Windows(destFile).Activate
> > Worksheets(topbotImportTab).Activate
> > topbotImportCell.Select
> > Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> > SkipBlanks:=False, Transpose:=False
> > ActiveWorkbook.Save
> > MsgBox "Changes to " & destFile & " saved."
> >

 
Reply With Quote
 
=?Utf-8?B?cm9ja2hhbW1lcg==?=
Guest
Posts: n/a
 
      21st Jun 2007
I just found the solution on the web. It involves setting
IgnoreReadOnlyRecommended:=True in the Workbooks.open line.

Once this option is set, the pop up that prompts for the password still
comes up. However, unlike before, entering the correct password and clicking
"ok", not read-only, will open the destFile WITHOUT read-only set to true.

I have also tested the case where I intentionally clicked "read-only" when
the prompt comes up. As expected, the files opens as read=only.

Thanks for your efforts. Hope this solution is useful.


"rockhammer" wrote:

> Once the workbooks.open line executes, the activeworkbook becomes the opened
> workbook so sourceFile <> destFile.
>
> The destFile has a modify password set and also the open-read-only option
> set via File->Save As->Options->General, etc.
>
> What I am experiencing is that when destFile is opened via the vb code I
> have, the normal popup that prompts for the password shows up. However,
> unlike when I open destFile via File->Open, even if I entered the correct
> password and click "ok" (not "read only"), destFile is still opened as
> read-only. Therefore the line that saves the file generates a run-time error.
>
> Thanks.
>
>
> "JLGWhiz" wrote:
>
> > This code (copied from your post) indicates that the destination file is the
> > same as the source file, same workbook, so I guess I don't understand the
> > question.
> >
> > sourceFile = ActiveWorkbook.Name
> > Workbooks.Open Filename:=sourceFileName, Notify:=False
> > fileOpened = True
> > destFile = ActiveWorkbook.Name
> >
> > Is it the worksheet that is protected within the workbook?
> >
> >
> > "rockhammer" wrote:
> >
> > > I have a macro in sourceFile which opens a destFile to copy data from
> > > sourceFile into destFile and then tries to save the destFile. My destFile in
> > > this case is one which has a modify password set and also has the open
> > > read-only recommended option set.
> > >
> > > What I am experiencing is that even though I enter the password when the
> > > prompt comes up when the destFile is opened and I click "ok" instead of "read
> > > only", the destFile is still opened as read-only.
> > >
> > > My question is: Is there a way to modify my code such that the destFile will
> > > NOT be opened read only when the proper password is entered when prompted?
> > > Excerpts of my code below - it all works except that destFile is always
> > > opened read only no matter what and therefore the line that saves the
> > > destFile gives an error.
> > >
> > > Thanks a lot.
> > >
> > > ' this is the file open sub
> > > Sub threed_file_open()
> > > fileOpened = False
> > > Application.DisplayAlerts = False
> > > Application.ScreenUpdating = False
> > > If Not fileSelected Then
> > > MsgBox "No 3D template file selected yet!"
> > > Exit Sub
> > > End If
> > > sourceFile = ActiveWorkbook.Name
> > > Workbooks.Open Filename:=sourceFileName, Notify:=False
> > > fileOpened = True
> > > destFile = ActiveWorkbook.Name
> > > Windows(sourceFile).Activate
> > > Application.DisplayAlerts = True
> > > Application.ScreenUpdating = True
> > > End Sub
> > >
> > >
> > > ' this is the code which does the copying & saving
> > > Windows(sourceFile).Activate
> > > topbot.Activate ' this is the tab in sourceFile I want to copy from
> > > Range(topbotExport1stCell, topbotExportLastCell).Select
> > > Selection.Copy
> > > Windows(destFile).Activate
> > > Worksheets(topbotImportTab).Activate
> > > topbotImportCell.Select
> > > Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> > > SkipBlanks:=False, Transpose:=False
> > > ActiveWorkbook.Save
> > > MsgBox "Changes to " & destFile & " saved."
> > >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening a recommended read only file as non read only Crauwf Microsoft Excel Programming 2 10th Dec 2008 08:25 AM
read .lnk files, modify the data and rewrite the file Frank Microsoft VC .NET 7 25th Jan 2007 08:49 PM
Difficult Question: Read/Modify file =?Utf-8?B?YW5rMmdv?= Microsoft Dot NET 2 13th Jan 2007 04:28 AM
How do I modify a Read-Only file? =?Utf-8?B?RnJvc3R5?= Microsoft Word Document Management 1 17th Mar 2005 10:12 PM
Excel VBA - Read and modify the chart data range rcatarino Microsoft Excel Programming 0 6th Apr 2004 01:19 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:51 AM.