Copy Drawing Sheet

Copy Drawing Sheet

Anonymous
Not applicable
414 Views
4 Replies
Message 1 of 5

Copy Drawing Sheet

Anonymous
Not applicable
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
0 Likes
415 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
I tested this code on a couple of simple drawings and it seems to work fine.
Could you test this same workflow via the user interface and see if you are
able to copy the sheets over? Also, test the code on other drawings to make
sure the problem is not document-specific.

Sanjay-

wrote in message news:5267432@discussion.autodesk.com...
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
0 Likes
Message 3 of 5

Anonymous
Not applicable
Thanks. It seemed the problem was document specific, since the code worked for a different drawing. Do you have any idea what might cause such a problem? That way I might not have to spend hours in the future trying to figure out a way to fix my code when it's not wrong.

One more thing. This code is intended to copy all the sheets from the drawings in one directory into one different drawing. It always gives an error message when trying to copy one particular drawing. I'm wondering if that could be due to something similar and what I might do to be able to fix that problem.

The error message occurs on the same line as previously, but this time it's

Run-time error '-2147467259 (80004005)':
Method 'CopyTo' of object '_IRxSheet' failed


Interestingly, if I debug the error and step through the line, it performs the method without error. This is something that really baffles me and I'd like to know what's going on. Thanks again for your help already.

-Tobe
0 Likes
Message 4 of 5

Anonymous
Not applicable
Would you be able to post the drawing in question? I don't have any ideas
offhand.

Sanjay-

wrote in message news:5268104@discussion.autodesk.com...
Thanks. It seemed the problem was document specific, since the code worked
for a different drawing. Do you have any idea what might cause such a
problem? That way I might not have to spend hours in the future trying to
figure out a way to fix my code when it's not wrong.

One more thing. This code is intended to copy all the sheets from the
drawings in one directory into one different drawing. It always gives an
error message when trying to copy one particular drawing. I'm wondering if
that could be due to something similar and what I might do to be able to fix
that problem.

The error message occurs on the same line as previously, but this time it's

Run-time error '-2147467259 (80004005)':
Method 'CopyTo' of object '_IRxSheet' failed


Interestingly, if I debug the error and step through the line, it performs
the method without error. This is something that really baffles me and I'd
like to know what's going on. Thanks again for your help already.

-Tobe
0 Likes
Message 5 of 5

Anonymous
Not applicable
Here's the drawing. I've done some experimenting and noticed that the same problem occurs with several other drawings, also. I could post those, too, if you thought that might be helpful. Thanks again for your help, and good luck!
0 Likes