Handling 2 workbooks
Hi !
-Running Windows2k pro and Excel97
I work with two workbooks and want to export several worksheets from one
workbook to the other.
Here's my (BAD) code :
'================================================= ==================================
Sub TestExport()
Dim Source$, Destination$, SrcSheetName$()
ReDim SrcSheetsName$(1 To ActiveWorkbook.Worksheets.Count)
Source$ = ThisWorkbook.Name
Destination$ = "C:\Bulletins\3F\Bulletins3F.xls"
intPtr2 = 1
For intPtr1 = 1 To ActiveWorkbook.Worksheets.Count
strTemp1 = Right(Sheets(intPtr1).Name, 2)
If InStr(strTemp1, " P") Then
SrcSheetsName$(intPtr2) = Sheets(intPtr1).Name
intPtr2 = intPtr2 + 1
End If
Next intPtr1
intPtr2 = intPtr2 - 1
For intPtr1 = 1 To intPtr2
If SheetExists(Workbooks(Destination$).Sheets(SrcShee tsName$(intPtr1)))
Then
Workbooks(Destination$).Sheets(SrcSheetsName$(intP tr1)).Delete
End If
Workbooks(Source$).Sheets(SrcSheetsName$(intPtr1)) .Move
After:=Workbooks(Destination$).Sheets(1)
Next intPtr1
End Sub
'==============================
Public Function SheetExists(shtname As String) As Integer
Dim tptr%, tnbsheets%
SheetExists = 0
tnbsheets% = ActiveWorkbook.Worksheets.Count
For tptr% = 1 To tnbsheets%
If Worksheets(tptr%).Name = shtname Then
SheetExists = 1
Exit Function
End If
Next tptr%
End Function
'==============================
Question : how can I put that to work ??
Thanks by advance for your help and regards from Belgium,
Herve+
|