analogkid2digitalman
Programmer
Hello:
I am writing a macro to insert data from one workbook (source) into another workbook comprised of one sheet (target)that is protected. No real previous VBA experience.
In code snippet below, I activate my source worksheet, define my copy range (1st With/End With block) and copy it.
Then I open my protected target workbook, activate it, try to unprotect it. Then the 2nd With/End With block inserts and pastes the lines of data into the target. Then reprotect and save and close the target workbook.
Data does not get pasted to target, just rows of blank cells.
The code, as shown with the Protect and Unprotect lines commented out, works perfectly if the taget workbook is unptotected.
Any ideas?
Thanks
-Pete
' Compile a range of output for valid entries, then write data to archive
' Need at least 1 valid entry so that ranges below are valid thus check if b at least zed
If b >= 0 Then
Workbooks("TubingCost.xls"
.Activate
With Worksheets("Summary"
.Range(.Cells(a, 1), .Cells(a + b, c)).Select
Selection.Copy
End With
Workbooks.Open DatabasePath
Workbooks("TubingHistory.xls"
.Activate
' Worksheets("TubingHist"
.Unprotect BUG- ONLY WRITES LINES OF BLANK DATA
With Worksheets("TubingHist"
.Range(.Cells(a1, 1), .Cells(a1 + b, c)).Select
Selection.Insert Shift:=xlDown
End With
' Worksheets("TubingHist"
.Protect BUG- ONLY WRITES BLANK DATA
Workbooks("TubingHistory.xls"
.Close SaveChanges:=True
Workbooks("TubingCost.xls"
.Activate
Worksheets("Summary"
.Activate
End If
I am writing a macro to insert data from one workbook (source) into another workbook comprised of one sheet (target)that is protected. No real previous VBA experience.
In code snippet below, I activate my source worksheet, define my copy range (1st With/End With block) and copy it.
Then I open my protected target workbook, activate it, try to unprotect it. Then the 2nd With/End With block inserts and pastes the lines of data into the target. Then reprotect and save and close the target workbook.
Data does not get pasted to target, just rows of blank cells.
The code, as shown with the Protect and Unprotect lines commented out, works perfectly if the taget workbook is unptotected.
Any ideas?
Thanks
-Pete
' Compile a range of output for valid entries, then write data to archive
' Need at least 1 valid entry so that ranges below are valid thus check if b at least zed
If b >= 0 Then
Workbooks("TubingCost.xls"
With Worksheets("Summary"
.Range(.Cells(a, 1), .Cells(a + b, c)).Select
Selection.Copy
End With
Workbooks.Open DatabasePath
Workbooks("TubingHistory.xls"
' Worksheets("TubingHist"
With Worksheets("TubingHist"
.Range(.Cells(a1, 1), .Cells(a1 + b, c)).Select
Selection.Insert Shift:=xlDown
End With
' Worksheets("TubingHist"
Workbooks("TubingHistory.xls"
Workbooks("TubingCost.xls"
Worksheets("Summary"
End If