Another VBA question

Please post any questions regarding the program here.

Moderator: 2020vision

Another VBA question

Postby Royville » Fri Jul 09, 2010 9:06 am

Hi All,

I want to save 2 worksheets from my existing workbook to a new workbook but I can't seem to manage it some how. I have managed to save a single sheet, but could you have a look at my code please and tell me how to make it save 2 sheets, eg "List" and "Results".


Code: Select all
Dim wb As Workbook

    Worksheets("Results").Copy
    Set wb = ActiveWorkbook
    wb.SaveAs "C:\Res" & Format(Date, "dmmm") & ".xls"
    wb.Close


Also, is it possible to include the 'Time' when saving as well as the 'Date'?

Many thanks
Roy.
Royville
 
Posts: 65
Joined: Wed Apr 21, 2010 4:50 pm
Location: UK Midlands

Postby osknows » Fri Jul 09, 2010 3:46 pm

Hi Roy,

I think this should work

Code: Select all
Option Explicit

Sub test()
'opens specified Workbook, copies Worksheets named 'List' & 'Results' from
'workbook this code is run from to specified Workbook AFTER the Worksheet named 'Sheet3'
Dim path As String
Dim filename As String
Dim extension As String
Dim newfilename As String

path = "C:\Users\osknows\Desktop\"
filename = "Book3.xlsx"     

'open workbook to paste into
Application.Workbooks.Open (path & filename)

'copy sheets
ThisWorkbook.Sheets(Array("List", "Results")).Copy After:=Workbooks(filename).Sheets("Sheet3")

'save opened workbook with timestamp and close
extension = "." & Split(filename, ".")(1)
newfilename = Split(filename, ".")(0) & Format(Now(), " mm_dd_yyyy hhmmAMPM") & extension
Workbooks(filename).SaveAs filename:=path & newfilename
Workbooks(newfilename & extension).Close
End Sub
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby Royville » Fri Jul 09, 2010 5:00 pm

Thanks Oz,

Works great!
Much appreciated

Roy.
Royville
 
Posts: 65
Joined: Wed Apr 21, 2010 4:50 pm
Location: UK Midlands


Return to Help

Who is online

Users browsing this forum: Google [Bot] and 34 guests

Sports betting software from Gruss Software


The strength of Gruss Software is that it’s been designed by one of you, a frustrated sports punter, and then developed by listening to dozens of like-minded enthusiasts.

Gruss is owned and run by brothers Gary and Mark Russell. Gary discovered Betfair in 2004 and soon realised that using bespoke software to place bets was much more efficient than merely placing them through the website.

Gary built his own software and then enhanced its features after trialling it through other Betfair users and reacting to their improvement ideas, something that still happens today.

He started making a small monthly charge so he could work on it full-time and then recruited Mark to help develop the products and Gruss Software was born.

We think it’s the best of its kind and so do a lot of our customers. But you can never stand still in this game and we’ll continue to improve the software if any more great ideas emerge.