Problem solved.
Thanks anyway.
I used the following command. -
Option Explicit
-
'Put a reference to:
-
'Microsoft Excel (highest number) Object Library
-
Private xlapp As Excel.Application
-
Private xlapp2 As Excel.Application
-
Dim wkbWorkBook As Excel.Workbook
-
Dim wksSheet As Excel.Worksheet
-
Dim wkb2 As Excel.Workbook
-
Dim wks2 As Excel.Worksheet
-
'Private Const thePath As String = "C:\"
-
Private SelectedFile As String
-
Private CounterTab As Integer
-
-
Private Sub Command1_Click()
-
Set xlapp = New Excel.Application
-
'xlapp.Workbooks.Open thePath & "pinpon.xls"
-
xlapp.Workbooks.Open SelectedFile
-
CounterTab = 2
-
Set wksSheet = xlapp.Worksheets(CounterTab)
-
wksSheet.Activate
-
MsgBox xlapp.ActiveSheet.Range("A3").Value
-
xlapp.ActiveSheet.Range("A1").Select
-
Selection.Copy
-
'PastetoNewFile
-
wksSheet.Activate
-
xlapp.ActiveWorkbook.Close savechanges:=False, FileName:=SelectedFile
-
Set wksSheet = Nothing
-
xlapp.Quit
-
Set xlapp = Nothing
-
End Sub
-
-
Private Sub PastetoNewFile()
-
Set xlapp2 = New Excel.Application
-
Set wkb2 = xlapp2.Workbooks.Add
-
'Here: you did not referenced correct objects:
-
wkb2.Worksheets.Add
-
wkb2.Worksheets("Sheet1").Activate
-
'In Italy the above is called differently...
-
'wkb2.Worksheets("Foglio1").Activate
-
wkb2.ActiveSheet.Paste
-
wkb2.Close savechanges:=True, FileName:=thePath & "new.xls"
-
Set wkb2 = Nothing
-
xlapp2.Quit
-
Set xlapp2 = Nothing
-
End Sub
Last edited by debasisdas; January 3rd, 2009 at 05:16 AM.
Reason: Added code tags for better formatting.
|