Message 1 of 5
Copy Drawing Sheet

Not applicable
08-14-2006
05:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey. I'm brand new to VBA and I'm hoping someone can help me. I'm trying to copy all the sheets of one drawing into another drawing file. This sub won't run without giving me an error message stating:
Run-time error '5':
Invalid procedure call or argument
If anyone knows what I'm doing wrong or has any insight into how I could make this better, let me know.
Public Sub OpenDrawing(FileToOpen As String)
' References the file into which sheets are going to be copied
Dim oMasterDrawing As Document
Set oMasterDrawing = ThisDocument
Dim oMaster As DrawingDocument
Set oMaster = oMasterDrawing
' References the file from which sheets are going to be copied
Dim oDocDrawing As Document
Set oDocDrawing = ThisApplication.Documents.Open(FileToOpen)
Call oDocDrawing.Activate
Dim oDrawing As DrawingDocument
Set oDrawing = oDocDrawing
' Ensures that the open file is indeed a drawing file
If oDrawing.DocumentType = oMaster.DocumentType Then
' Activate the drawing with the sheets to be copied
Call oDrawing.Activate
Dim intNumSheets As Integer
intNumSheets = oDrawing.Sheets.Count
Dim intIndex As Integer
' Copy each sheet from the active drawing into the master drawing
For intIndex = 1 To intNumSheets
Call oDrawing.Sheets.Item(intIndex).Activate
Call oDrawing.ActiveSheet.CopyTo(oMaster) ' **The error occurs here**
Next
' Close the drawings from which files have been copied
Call oDrawing.Close
Call oDocDrawing.Close
End If
End Sub
Run-time error '5':
Invalid procedure call or argument
If anyone knows what I'm doing wrong or has any insight into how I could make this better, let me know.
Public Sub OpenDrawing(FileToOpen As String)
' References the file into which sheets are going to be copied
Dim oMasterDrawing As Document
Set oMasterDrawing = ThisDocument
Dim oMaster As DrawingDocument
Set oMaster = oMasterDrawing
' References the file from which sheets are going to be copied
Dim oDocDrawing As Document
Set oDocDrawing = ThisApplication.Documents.Open(FileToOpen)
Call oDocDrawing.Activate
Dim oDrawing As DrawingDocument
Set oDrawing = oDocDrawing
' Ensures that the open file is indeed a drawing file
If oDrawing.DocumentType = oMaster.DocumentType Then
' Activate the drawing with the sheets to be copied
Call oDrawing.Activate
Dim intNumSheets As Integer
intNumSheets = oDrawing.Sheets.Count
Dim intIndex As Integer
' Copy each sheet from the active drawing into the master drawing
For intIndex = 1 To intNumSheets
Call oDrawing.Sheets.Item(intIndex).Activate
Call oDrawing.ActiveSheet.CopyTo(oMaster) ' **The error occurs here**
Next
' Close the drawings from which files have been copied
Call oDrawing.Close
Call oDocDrawing.Close
End If
End Sub