Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,570
- Office Version
- 365
- 2016
- Platform
- Windows
I've run into a little stumbling block that I hope someone can assist with.
It the portion of code below, am copying an existing a worksheet and renaming it, and then with that new worksheet, trying to remove any buttons (shapes) on the page. This code used to work, but for some reason it has stopped. I'm here because I'm trying to figure out what might have changed.
The line in red is leaving me with an "Application-Defined or Object-defined error". I can step through the code, and in this line, it will step through 4 deletes before it hits the error.
shnm = "EVL" (the newly created worksheet's name).
There are 3 shapes, 2 "buttons" and a 3 rectangle that partially obscures the buttons, in columns Q:AG.
The sheet is unprotected and visible. A second workbook is open, but it does not appear to be inadvertently being applied these changes.
Thoughts?
It the portion of code below, am copying an existing a worksheet and renaming it, and then with that new worksheet, trying to remove any buttons (shapes) on the page. This code used to work, but for some reason it has stopped. I'm here because I'm trying to figure out what might have changed.
Rich (BB code):
Sub dist_create()
'Stop
Application.ScreenUpdating = False
Dim filePath As String
Dim tc As Boolean
Dim CList(1 To 5) As String
Dim rw As Integer
Dim sh As Worksheet
Dim bLeft, bRight, c As Range
Dim arrFolders() As String
Dim i As Integer
Dim strPath As String
'setup sheets staff
'check if distributables have been prepared already
mntxt = MonthName(Month(inq_date))
daytext = WeekdayName(Weekday(inq_date), True)
crtyr = Year(Now)
filePath = distpath & crtyr & "\" & mntxt & "\" & Format(Day(inq_date), "00") & " " & UCase(daytext) & "\"
nfn = "WS " & Format(inq_date, "dd-mmm-yy") & ".xlsx"
'create and save new target workbook
filePath = filePath & nfn
If FileExists(filePath) = True Then Kill (filePath) 'delete previous file for now
Workbooks.Add.SaveAs Filename:=filePath
Set wb_daily = Workbooks(nfn)
'copy sheets
arrNames = Array("MASTER", "EVL", "EVE", "LWP", "WPL", "WPE", "RPL", "RPE", "HPL", "HPE", "BPL", "BPE", "CUL", "CUE2", "CUE1", "CWP", "CRP", "LSP")
'create raw sheets
'Stop
For i = 0 To 17
shnm = arrNames(i)
Debug.Print shnm
Set ssh = Nothing
On Error Resume Next
Set ssh = ThisWorkbook.Sheets("Master")
On Error GoTo 0
If Not ssh Is Nothing Then
ssh.Copy After:=wb_daily.Sheets(1)
ActiveSheet.Name = shnm
'sheets are hidden
End If
If shnm <> "MASTER" Then
With ActiveSheet
.Unprotect
'eliminate buttons
With ActiveSheet.Columns("Q:AG")
For Each shp In .Parent.Shapes
If Not Intersect(shp.TopLeftCell, .Cells) Is Nothing Then shp.Delete
Next shp
End With
With ActiveSheet.Range("D1:R9")
For Each shp In .Parent.Shapes
If Not Intersect(shp.TopLeftCell, .Cells) Is Nothing Then shp.Delete
Next shp
End With
'eliminate staffing range
.Columns("S:AG").Clear
.Range("O4") = ActiveSheet.Name
.Protect
End With
End If
Next i
.. .. ..
The line in red is leaving me with an "Application-Defined or Object-defined error". I can step through the code, and in this line, it will step through 4 deletes before it hits the error.
shnm = "EVL" (the newly created worksheet's name).
There are 3 shapes, 2 "buttons" and a 3 rectangle that partially obscures the buttons, in columns Q:AG.
The sheet is unprotected and visible. A second workbook is open, but it does not appear to be inadvertently being applied these changes.
Thoughts?