Results 1 to 6 of 6

Exporting and Saving Spreadsheet

Threaded View

BazzaBoy Exporting and Saving... 07-19-2009, 09:15 AM
royUK Re: Exporting and Saving... 07-19-2009, 09:31 AM
royUK Re: Exporting and Saving... 07-19-2009, 09:59 AM
BazzaBoy Re: Exporting and Saving... 07-19-2009, 05:47 PM
royUK Re: Exporting and Saving... 07-20-2009, 03:58 AM
royUK Re: Exporting and Saving... 07-20-2009, 04:06 AM
  1. #1
    Registered User
    Join Date
    06-29-2008
    Location
    Perth, Australia
    MS-Off Ver
    MS Office 2003
    Posts
    87

    Exporting and Saving Spreadsheet


    I have created a macro which copies the content of one of the sheets of a workbook, on to a new workbook and then saves the new workbook as 'temp.xls' on the desktop.
    Sub Export_Data()
    '
    ' Export_Data Macro
    ' Macro recorded 14/07/2009 by Behram
    '
    
    '
    If MsgBox("Please ensure this workbook is the ONLY Excel file open. Are you sure?", vbYesNo + vbQuestion) = vbNo Then
        Exit Sub
        Else
        Sheets("Ship_Data").Select
        Range("A1").Select
        Workbooks.Add
        Sheets("Sheet2").Select
        ActiveWindow.SelectedSheets.Delete
        Sheets("Sheet3").Select
        ActiveWindow.SelectedSheets.Delete
        ActiveWindow.ActivateNext
        Cells.Select
        Selection.Copy
        Range("A1").Select
        ActiveWindow.ActivateNext
        ActiveSheet.Paste
        Range("A3").Select
        ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
        "Sheet1!AB120", TextToDisplay:="N O T E S"
        Range("AA119").Select
        ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
            "Sheet1!A1", TextToDisplay:="H O M E"
        Range("A1").Select
        Application.CutCopyMode = False
        ChDir "C:\Documents and Settings\John\Desktop"
        ActiveWorkbook.SaveAs Filename:= _
            "C:\Documents and Settings\John\Desktop\temp.xls", FileFormat:=xlNormal, _
            Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
            CreateBackup:=False
        ActiveWindow.Close
        Sheets("D_Survey").Select
    End If
    End Sub
    I would like to make a few changes to it:
    1. The name of the file should be picked-up from cell E7 of the sheet from which the data is being copied, instead of calling the new file 'temp.xls'
    2. As you will see in the macro, I have deleted the two extra sheets that come with a new workbook. But what if the current user has changed his options to create a new workbook with only one sheet. In that case the script will stall. So, I need to delete the two extra sheets, only if they exist. Alternatively, the macro can create the new workbook with only one sheet, regardless of that user's options.
    3. The macro saves the file to John's Desktop. But what if the current user is not John. Can I replace 'John' in the path to something like 'current_user'?
    Any help will be appreciated.

    Thanks in advance.


    Last edited by BazzaBoy; 07-19-2009 at 05:48 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1