Hi! Thanks so much for stepping in to offer assistance!
Logit ... I commented out the line you pointed out in the CopyModule code. It stopped on this line with the error "Method 'VBProject' of object '_Workbook' failed. This is a new one for me.
wb_mat.VBProject.VBComponents(strModuleName).Export strTempFile
Andy, your approach seems simple enough so I gave it a go. I moved the simple lines of code for the shapes into that worksheet's object code. BTW, here is the code for the macro emedded buttons on the worksheet being copied to a new book.
Sub Group6_Click() 'PRINT
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
End Sub
Sub Group9_Click() 'CLOSE
With ActiveWorkbook
ActiveSheet.Protect
.Save
.Close
End With
End Sub
The CopyModule code is eliminated altogether from the emailing code.
However, I run into a problems even before this associated with saving the copied workbook initially. The process of copying the worksheet to a new book is initially created in this module. (This creation is not the one that is emailed. The one emailed is the same worksheet but has some button functionality disabled for the recipient). Refer to this code ...
Private Sub uf2_create_Click()
Dim f_range As Range
...
m1 = Application.WorksheetFunction.Match(uf2_srf.uf2cb_worange.Value, ws_sheet2.Range("O2:O21"), 0)
rng_low = Application.WorksheetFunction.Index(ws_sheet2.Range("K2:O21"), m1, 1)
rng_hi = Application.WorksheetFunction.Index(ws_sheet2.Range("K2:O21"), m1, 2)
sname = Format(rng_low, "ddmmmyy") & "-" & Format(rng_hi, "ddmmmyy")
Application.ScreenUpdating = False
With ws_srf
.Visible = True
.Copy
.Visible = False
End With
Application.ScreenUpdating = True
ActiveSheet.Name = sname
Set ws_tsrf = Worksheets(sname)
With ws_tsrf
.Unprotect
sname = "SRF_WP_" & sname & ".xlsx"
fname = "H:\Materials Tracking\Reports\" & sname
ui1 = InputBox("Please enter user's initials:", vbInformation, "REQUIRED INFORMATION")
.Range("AB1") = uf2_srf.uf2cb_worange.Value
.Range("B32") = " substance (" & un1 & ")"
tr = 8
nr = 0
For i = 51 To 72
If ws_sheet2.Cells(i, 3) > 0 Then
.Cells(tr - 1, 1) = "90000"
.Cells(tr - 1, 3) = "Salt"
.Cells(tr - 1, 2) = ws_sheet2.Cells(i, 3)
.Cells(tr - 1, 4) = ui1
wo = ws_sheet2.Cells(i, 2)
.Cells(tr, 11) = Right(wo, 1)
.Cells(tr, 10) = Mid(wo, 5, 1)
.Cells(tr, 9) = Mid(wo, 4, 1)
.Cells(tr, 8) = Mid(wo, 3, 1)
.Cells(tr, 7) = Mid(wo, 2, 1)
.Cells(tr, 6) = Left(wo, 1)
nr = nr + 1 'change to 1
If nr = 12 Then 'add page
.Rows("1:33").Copy .Range("34:34")
.Range("A41:AN64") = ""
tr = 41
Else
tr = tr + 2
End If
End If
Next i
.Protect
MsgBox "New report visible behind this window.", vbExclamation, "REPORT COMPLETED"
uf2_srf.uf2_create.Enabled = False
.SaveAs Filename:=fname
Set wb_tsrf = Workbooks(sname)
End With
End Sub
This code breaks at the line in red when it tries to save. Since the new workbook has vb associuated to it (in the worksheet object) it will not allow it to save with that (.xlsx) extension.
If I change the extension to ".xlsm" in the line in blue ... I get "This extension can not be used with the selected file type. Change the file extension in the File name text box or select a different file type by changing the Save as type." as in breaks at the same line as above in red. It doesn't appear as though I can save the newly created workbook with the vba in the sheet.
Bookmarks