excel vba - trouble with read only code

  • Thread starter Thread starter chief
  • Start date Start date
C

chief

Here is the rundown of what happens in this project

1. The user opens the page
2. Fills out the required info
3. clicks on the command button 1 to save and print, this saves th
file as the invoice # in a specific location
4. when they open the page again, it returns a sequential invoice #
5. they then must click on another button in order to make the save
client info disappear
6. once they do this, certain cells which are not for data entry wil
become protected
7. the process recycles at step 2

In Userform1 I have

Private Sub CommandButton1_Click()
ActiveWorkbook.Save
Sheet1.SaveAs FileName:="Q:\SALES POs\" & Range("K5").Value
Range("A1:M56").PrintOut
ActiveWorkbook.Close

End Sub

In This Workbook I have

Private Sub Workbook_Open()

Sheet1.Unprotect
Range("F7").Select
Range("K3") = Now()
Range("K3").NumberFormat = "mmmm d, yyyy"
With Me.Sheets("Sheet1").Range("K5")
.Value = .Value + 1
.NumberFormat = "0000"
End With
UserForm2.Show

End Sub

In SHEET 1 I have

Private Sub CommandButton1_Click()
Range(" C9:D15,E15:F15,I9:L15,B19:B38,C19:C38,D19:D38,K39:
L40,K44:L44,D43:E43,C47:F49,K54:L54").ClearContents
Range(" C9:D15,E15:F15,I9:L15,B19:B38,C19:C38,K39:L40,K44:
L44,D43:E43,C47:F49,K54:L54").Select
Selection.Locked = False
Sheet1.Protect
Range("E8").Select
End Sub

What would be the code in order for this series of events to happen:

1. Person clicks on userform 1 in order to save the file to the "Q
location
2. The newly saved file becomes read only
3. The file is copied and pasted into "H:\RETAIL SALES POs\"

Beyond that, is there some type of way to make it so that the save
file in "Q" or "H" cannot be copied by someone manually and then paste
to another location where that person can change the information insid
that saved sheet?

I think it sounds confusing but I don't think it has to be

Any ideas
 
I think this is what you wrote:

Option Explicit
Private Sub CommandButton1_Click()
Dim myFileName As String
Dim QPath As String
Dim HPath As String

QPath = "Q:\SALES POs\"
HPath = "H:\RETAIL SALES POs\"

myFileName = Sheet1.Range("K5").Value
With ActiveWorkbook
.Save
.SaveCopyAs Filename:=QPath & myFileName
SetAttr pathname:=QPath & myFileName, Attributes:=vbReadOnly
FileCopy Source:=QPath & myFileName, Destination:=HPath & myFileName
Sheet1.Range("a1:m56").PrintOut
'.Close savechanges:=False
End With

End Sub

I commented out the .close line--it's a pain while testing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top