Excel
-
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
-
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
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
-
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
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.WorksheetSet 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 NextApplication.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
-
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
hi, Did u tried with worksheet.Add method????
-
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.WorksheetSet 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 NextApplication.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
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