L
L. Howard
With this code in a standard module in a workbook named "Copy of Vehicle Quotation Internal V7a" and I save it as a workbook named "My New Workbook 1" how can I get the code to now reference the new name.
Where in the code below this line of code:
Set wbSource = Workbooks("Copy of Vehicle Quotation Internal V7a.xlsm")
Will the equivalent of this:
Set wbSource = Workbooks("My New Workbook 1.xlsm")
I tried using a variable where
Dim wbName As WorkBook
is set to
ActiveWorkbook.Name
with
Set wbSource = Workbooks(wbName & ".xlsm")
but it errors out wanting an object or type mismatch depending on either
Dim wbName As Syring or Dim wbName As WorkBook
Thanks.
Howard
Function IsFileOpen(FileName As String)
Dim iFilenum As Long
Dim iErr As Long
On Error Resume Next
iFilenum = FreeFile()
Open FileName For Input Lock Read As #iFilenum
Close iFilenum
iErr = Err
On Error GoTo 0
Select Case iErr
Case 0: IsFileOpen = False
Case 70: IsFileOpen = True
Case Else: Error iErr
End Select
End Function
Sub MyVQICopy()
Dim wbSource As Workbook
Dim wbDest As Workbook
If Not IsFileOpen("Income Report v2.xlsm") Then
Workbooks.Open ("Income Report v2.xlsm")
End If
Set wbSource = Workbooks("Copy of Vehicle Quotation Internal V7a.xlsm")
Set wbDest = Workbooks("Income Report v2.xlsm")
wbDest.Sheets("Sheet1").Range("J" & Rows.Count).End(xlUp)(2) = wbSource.Sheets("Sheet1").Range("B2").Value
wbDest.Sheets("Sheet1").Range("K" & Rows.Count).End(xlUp)(2) = wbSource.Sheets("Sheet1").Range("D3").Value
wbDest.Sheets("Sheet1").Range("L" & Rows.Count).End(xlUp)(2) = wbSource.Sheets("Sheet1").Range("B29").Value
wbDest.Sheets("Sheet1").Range("N" & Rows.Count).End(xlUp)(2) = wbSource.Sheets("Sheet1").Range("B19").Value
wbDest.Sheets("Sheet1").Range("O" & Rows.Count).End(xlUp)(2) = Time
wbSource.Sheets("Sheet1").Range("B2,D3,B29,B19").ClearContents
End Sub
Where in the code below this line of code:
Set wbSource = Workbooks("Copy of Vehicle Quotation Internal V7a.xlsm")
Will the equivalent of this:
Set wbSource = Workbooks("My New Workbook 1.xlsm")
I tried using a variable where
Dim wbName As WorkBook
is set to
ActiveWorkbook.Name
with
Set wbSource = Workbooks(wbName & ".xlsm")
but it errors out wanting an object or type mismatch depending on either
Dim wbName As Syring or Dim wbName As WorkBook
Thanks.
Howard
Function IsFileOpen(FileName As String)
Dim iFilenum As Long
Dim iErr As Long
On Error Resume Next
iFilenum = FreeFile()
Open FileName For Input Lock Read As #iFilenum
Close iFilenum
iErr = Err
On Error GoTo 0
Select Case iErr
Case 0: IsFileOpen = False
Case 70: IsFileOpen = True
Case Else: Error iErr
End Select
End Function
Sub MyVQICopy()
Dim wbSource As Workbook
Dim wbDest As Workbook
If Not IsFileOpen("Income Report v2.xlsm") Then
Workbooks.Open ("Income Report v2.xlsm")
End If
Set wbSource = Workbooks("Copy of Vehicle Quotation Internal V7a.xlsm")
Set wbDest = Workbooks("Income Report v2.xlsm")
wbDest.Sheets("Sheet1").Range("J" & Rows.Count).End(xlUp)(2) = wbSource.Sheets("Sheet1").Range("B2").Value
wbDest.Sheets("Sheet1").Range("K" & Rows.Count).End(xlUp)(2) = wbSource.Sheets("Sheet1").Range("D3").Value
wbDest.Sheets("Sheet1").Range("L" & Rows.Count).End(xlUp)(2) = wbSource.Sheets("Sheet1").Range("B29").Value
wbDest.Sheets("Sheet1").Range("N" & Rows.Count).End(xlUp)(2) = wbSource.Sheets("Sheet1").Range("B19").Value
wbDest.Sheets("Sheet1").Range("O" & Rows.Count).End(xlUp)(2) = Time
wbSource.Sheets("Sheet1").Range("B2,D3,B29,B19").ClearContents
End Sub