Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Excel

Excel

Scheduled Pinned Locked Moved Visual Basic
csharphelpquestionlearning
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Britnt7
    wrote on last edited by
    #1

    How is this coded in visual basic 6? I have gotten everything but this. copy coversheet1 from test.xls in c:\test directory paste or create coversheet1 to test2.xls in c:\test2 directory both excel documents exist but I need to transfer a sheet from one document to the other. Any help would be greatly appreciated. Thanks Beginner in VB.Net

    D R 3 Replies Last reply
    0
    • B Britnt7

      How is this coded in visual basic 6? I have gotten everything but this. copy coversheet1 from test.xls in c:\test directory paste or create coversheet1 to test2.xls in c:\test2 directory both excel documents exist but I need to transfer a sheet from one document to the other. Any help would be greatly appreciated. Thanks Beginner in VB.Net

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Actually, your question has nothing to do with VB. Rather, it's a question of knowing Excel object model, which I'm not that great with. After a cursory search through MSDN, I couldn't find a Copy method in the Worksheet object documentation. In theory, you'll have to open both workbooks in your Excel object (I'm not even sure this is possible!) Call some kind of copy method on the Worksheet object you're copying from and give it the workbook name to copy the sheet to. You'll probably also have to give it the name of a worksheet in your destination workbook so the Copy method knows where to put the copy in the worksheet order. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      1 Reply Last reply
      0
      • B Britnt7

        How is this coded in visual basic 6? I have gotten everything but this. copy coversheet1 from test.xls in c:\test directory paste or create coversheet1 to test2.xls in c:\test2 directory both excel documents exist but I need to transfer a sheet from one document to the other. Any help would be greatly appreciated. Thanks Beginner in VB.Net

        R Offline
        R Offline
        Ritesh1234
        wrote on last edited by
        #3

        Hi, This is what i got form MSDN ....................

        You can add one or more worksheets to the Worksheets collection by using the collection's Add method. The Add method returns the new Worksheet object. If you add multiple worksheets, the Add method returns the last worksheet added to the Worksheets collection. If the Before or After arguments of the Add method are omitted, the new worksheet is added before the currently active worksheet. The following example adds a new worksheet before the active worksheet in the current collection of worksheets:
        Dim wksNewSheet As Excel.Worksheet

        Set wksNewSheet = Worksheets.Add
        With wksNewSheet
        ' Work with properties and methods of the
        ' new worksheet here.
        End With
        You use the Worksheet object's Delete method to delete a worksheet from the Worksheets collection. When you try to programmatically delete a worksheet, Microsoft® Excel will display a message (alert); to suppress the message, you must set the Application object's DisplayAlerts property to False, as illustrated in the following example:
        Function DeleteWorksheet(strSheetName As String) As Boolean
        On Error Resume Next

        Application.DisplayAlerts = False
        ActiveWorkbook.Worksheets(strSheetName).Delete
        Application.DisplayAlerts = True
        ' Return True if no error occurred;
        ' otherwise return False.
        DeleteWorksheet = Not CBool(Err.Number)
        End Function
        Note When you set the DisplayAlerts property to False, always set it back to True before your procedure has finished executing, as shown in the preceding example.
        You can copy a worksheet by using the Worksheet object's Copy method. To copy a worksheet to the same workbook as the source worksheet, you must specify either the Before or After argument of the Copy method. You move a worksheet by using the Worksheet object's Move method. For example:
        Worksheets("Sheet1").Copy After:=Worksheets("Sheet3")
        Worksheets("Sheet1").Move After:=Worksheets("Sheet3")
        The next example illustrates how to move a worksheet so that it is the last worksheet in a workbook:
        Worksheets("Sheet1").Move After:=Worksheets(Worksheets.Count)

        I hope this will help u................:-> Regards, Ritesh

        B 1 Reply Last reply
        0
        • B Britnt7

          How is this coded in visual basic 6? I have gotten everything but this. copy coversheet1 from test.xls in c:\test directory paste or create coversheet1 to test2.xls in c:\test2 directory both excel documents exist but I need to transfer a sheet from one document to the other. Any help would be greatly appreciated. Thanks Beginner in VB.Net

          R Offline
          R Offline
          Ritesh1234
          wrote on last edited by
          #4

          hi, Did u tried with worksheet.Add method????

          1 Reply Last reply
          0
          • R Ritesh1234

            Hi, This is what i got form MSDN ....................

            You can add one or more worksheets to the Worksheets collection by using the collection's Add method. The Add method returns the new Worksheet object. If you add multiple worksheets, the Add method returns the last worksheet added to the Worksheets collection. If the Before or After arguments of the Add method are omitted, the new worksheet is added before the currently active worksheet. The following example adds a new worksheet before the active worksheet in the current collection of worksheets:
            Dim wksNewSheet As Excel.Worksheet

            Set wksNewSheet = Worksheets.Add
            With wksNewSheet
            ' Work with properties and methods of the
            ' new worksheet here.
            End With
            You use the Worksheet object's Delete method to delete a worksheet from the Worksheets collection. When you try to programmatically delete a worksheet, Microsoft® Excel will display a message (alert); to suppress the message, you must set the Application object's DisplayAlerts property to False, as illustrated in the following example:
            Function DeleteWorksheet(strSheetName As String) As Boolean
            On Error Resume Next

            Application.DisplayAlerts = False
            ActiveWorkbook.Worksheets(strSheetName).Delete
            Application.DisplayAlerts = True
            ' Return True if no error occurred;
            ' otherwise return False.
            DeleteWorksheet = Not CBool(Err.Number)
            End Function
            Note When you set the DisplayAlerts property to False, always set it back to True before your procedure has finished executing, as shown in the preceding example.
            You can copy a worksheet by using the Worksheet object's Copy method. To copy a worksheet to the same workbook as the source worksheet, you must specify either the Before or After argument of the Copy method. You move a worksheet by using the Worksheet object's Move method. For example:
            Worksheets("Sheet1").Copy After:=Worksheets("Sheet3")
            Worksheets("Sheet1").Move After:=Worksheets("Sheet3")
            The next example illustrates how to move a worksheet so that it is the last worksheet in a workbook:
            Worksheets("Sheet1").Move After:=Worksheets(Worksheets.Count)

            I hope this will help u................:-> Regards, Ritesh

            B Offline
            B Offline
            Britnt7
            wrote on last edited by
            #5

            Ritesh1234 wrote: You can copy a worksheet by using the Worksheet object's Copy method. To copy a worksheet to the same workbook as the source worksheet, you must specify either the Before or After argument of the Copy method. I am trying to copy a worksheet from one workbook to another workbook. From what I get from you is, copying a worksheet in the same workbook and not to a totally different workbook. I was able to add a sheet to the workbook but that doesn't solve the problem of copying the data over to it. This is my task. I am creating an excel document in Visual Basic code with 6 worksheets. Now I need to be able to create another sheet making it the cover sheet for that work book. I have another excel file that acts like a template as to what the cover sheet should look like. I need to copy that worksheet containing the cover sheet to the new file I created in visual basic. EX: Test.xls contains coverSheet Test2.xls contains 6 worksheets I need to take the coverSheet from test.xls and put that worksheet into test2.xls Is it possible to copy from one workbook to another different workbook? Thanks for the help:) Beginner in VB.Net

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups