Hello dear colleagues. Perhaps this topic was already discussed but I was unable to find similar thread so here's the problem.
I have a certain excel file. I am trying to write a code that will perform following steps.
By clicking on a button I would like to save a copy of this file with a speficific name that I am extracting from cell "E5" to a specific location and then write the name this file into a "database" file into a certain folder.
I am new to VBA and I tried to prepare the code myself but there is something wrong with it.
Here is the whole code:
I am getting a "Run-time error 438 - object doesnt support this property or method" in this part of the code:
Could someone please help me to understand why this error occurs?
Many thanks...
I have a certain excel file. I am trying to write a code that will perform following steps.
By clicking on a button I would like to save a copy of this file with a speficific name that I am extracting from cell "E5" to a specific location and then write the name this file into a "database" file into a certain folder.
I am new to VBA and I tried to prepare the code myself but there is something wrong with it.
Here is the whole code:
VBA Code:
Sub save_filename()
Dim Path As String
Dim filename As String
Dim wbCopy As Workbook
Dim wbDest As Workbook
Dim Fname As String
Dim lDestLastRow As Long
'Message box for file save confirmation
If MsgBox("Do you want to write a copy of this file into m:\files ?", vbYesNo + vbQuestion) = vbYes Then
Path = "m:\files"
filename = Range("E5").Value & ".xlsm"
ActiveWorkbook.SaveAs Path & filename
End If
'Defining source and destination workbooks
Set wbCopy = ActiveWorkbook
Set wbDest = Workbooks.Open("m:\files\DATABASE.xlsx")
'Copying filename that is located in "E5" cell
wbCopy.Sheets("Raport A3").Range("E5").Copy
lDestLastRow = wbDest.Cells(wbDest.Rows.Count, "A").End(xlUp).Offset(1).Row
wbDest.Sheets("Sheet1").Range("A" & lDestLastRow).Paste
Workbooks("DATABASE.xlsx").Close SaveChanges:=True
ActiveWorkbook.Close
Application.DisplayAlerts = False
Application.DisplayAlerts = True
End Sub
I am getting a "Run-time error 438 - object doesnt support this property or method" in this part of the code:
VBA Code:
lDestLastRow = wbDest.Cells(wbDest.Rows.Count, "A").End(xlUp).Offset(1).Row
Could someone please help me to understand why this error occurs?
Many thanks...