Hello, I have an excel file that creates a copy of one of my sheets and saves the sheet as a new workbook with a name constructed from info that the field agents are using. During the save process, one of my userforms is being exported and then imported to the new workbook during the creation of it. However, the VBA fails to import the userform tot to the new workbook and I receive a useform log file. The log file says 'Line 2: The Form or MDIForm name DriverReport is already in use; cannot load this form.'
In my VBA I have set to grab the useform named driverreport and rename the file when it gets exported. the frm. saves with the new name fine, but the log keeps saying that the name is already in use.
Below is my code. Any help will be very appreciated.
In my VBA I have set to grab the useform named driverreport and rename the file when it gets exported. the frm. saves with the new name fine, but the log keeps saying that the name is already in use.
Below is my code. Any help will be very appreciated.
VBA Code:
Private Sub CommandButton35_Click()
Workbooks("BEUS Digital 2.5.1 8.9.21.xlsm").Activate
Dim myValWU As Double
Dim strVehNum As String
Dim strName As String
Dim strShift As String
Dim strYear As String
Dim strPath As String
Dim strKW As String
Dim strWK As String
Dim sDate As String
Dim FSO As New FileSystemObject
Dim strFname As String
Dim DrNum As String
Dim Dr As String
Dim path As String
Dim FileName1 As String
Dim fn As String
strPath = Sheets("ALL APP LINKS").Range("B10")
strFname = Sheets("ALL APP LINKS").Range("B14")
strVehNum = Sheets("ALL APP LINKS").Range("B29") ' assumes vehicle number in B29
sDate = Format(Sheets("ALL APP LINKS").Range("B28"), "YYYYMMDD")
strShift = Sheets("ALL APP LINKS").Range("C30") ' assumes shift in B30
strName = Sheets("ALL APP LINKS").Range("B31")
Dr = Sheets("Tabelle1").Range("AF1").Value
DrNum = Sheets("Tabelle1").Range("AE1").Value
FileName1 = "DriverReport.frm"
path = "C:\Users\taneviv\Documents\DIGITAL TEST FORMS\"
ThisWorkbook.VBProject.VBComponents("DriverReport").Export _
fileName:="C:\Users\taneviv\Documents\DIGITAL TEST FORMS\DriverReport.frm"
fn = strPath & "\" & strFname & "_" & strVehNum & "_" & sDate & "_" & strShift & "_" & strName & "_" & Dr & "_" & DrNum & ".xlsm"
If Dir(fn) <> "" Then
End If
With Workbooks.Add(xlWBATWorksheet)
ThisWorkbook.Sheets(Array("Tabelle1")).Copy after:=.Sheets(1)
Application.DisplayAlerts = False
.Sheets(1).Delete
Application.DisplayAlerts = True
On Error Resume Next
Kill fn
.SaveAs fn, xlOpenXMLWorkbookMacroEnabled
.Close False
End With
Call importfrm
myValWU = Val(LBWU1.Caption)
myValWU = myValWU + 1
LBWU1.Caption = myValWU
Sheets("Tabelle1").Range("AE1").Value = LBWU1.Caption
Sheets("Tabelle1").Range("A2:U99,W2:AB99").ClearContents
End Sub