LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Save As and new workbook new name used in existing code

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").C learContents

End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save Workbook with existing Name in the Folder K[_2_] Excel Programming 3 June 26th 09 01:38 AM
save workbook without code vqthomf Excel Programming 1 February 7th 08 11:39 AM
How to save existing Workbook with a new new name, without changingthe open Workbook name? [email protected] Excel Programming 7 February 3rd 08 03:35 AM
Allowing xlBook.SaveAs in Access code to overwrite existing workbook? Ed from AZ Excel Programming 2 January 26th 08 08:16 PM
Save Workbook without VBA code Ken Loomis Excel Programming 4 March 24th 05 11:38 PM


All times are GMT +1. The time now is 06:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"