|
-
Nov 18th, 2001, 02:07 PM
#1
Thread Starter
New Member
Again Runtime Error 462 from Mocambique
Last week I posted in VB Questions, then I thought I solved, but I didn't!!
Here comes the code:
''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Command1_Click()
Dim xlApp As Object
Dim myPath As String
Dim myFile1 As String
Dim myFile2 As String
Dim myWorkbook As String
Set xlApp = CreateObject("Excel.Application")
myPath = App.Path
myWorkbook = myPath & "\" & myFile1
With xlApp
.Visible = False
.Workbooks.Open myWorkbook, 3
.ActiveWorkbook.Unprotect "myCode"
.myWorkbook = myPath & "\" & myFile2
.Workbooks.Open myWorkbook, 3
.Workbooks(myFile).Activate
.Worksheets(mySheet).Select
.Worksheets(mySheet).Unprotect "myCode"
.Worksheets(mySheet).Copy After:=Workbooks(myFile1).Worksheets(2)
.Workbooks.Application.CutCopyMode = False
.Workbooks(myFile2).Close False
.ActiveWorkbook.Protect "myCode", True
End With
xlApp.Visible = True
Set xlApp = Nothing
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''
This is an automatic copy what I want my program to do every time I start Excel.
If I now continuing working in Excel while my VB project is still running and than quit Excel and I want to enter again then I get the Runtime Error 462 about a remote machine.
It give this error only because of the sheet copy line!!
Who can help me????
-
Nov 23rd, 2001, 10:33 AM
#2
Thread Starter
New Member
Hi, everybody with the 462 runtime error problem.
It seems that I have to respond my own questions.
Is 462 not an interesting problem or is it too difficult???
I'am only a beginner, so I don't know!!
Here is the code what works, every line must be defined by a dimensioned object, otherwise you cannot repeat your code without first quitting your VB program.
Private Sub Command1_Click()
Dim xlApp As Object
Dim xlBook1 As Excel.Workbook
Dim xlBook2 As Excel.Workbook
Dim xlSheet1 As Excel.Worksheet
Dim xlSheet2 As Excel.Worksheet
Dim xlSheet3 As Excel.Worksheet
Dim myFile1 As String
Dim myFile2 As String
myPath = App.Path
myFile1 = myPath & "\.............."
myFile2 = myPath & "\.............."
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.DisplayAlerts = False
Set xlBook1 = GetObject(myFile1)
xlApp.DisplayAlerts = True
xlApp.Windows(myFile1).Visible = True
Set xlSheet1 = xlBook1.Worksheets(myWS1)
Set xlSheet3 = xlBook1.Worksheets(myWS2)
xlSheet1.Select
xlBook1.Unprotect "myCode"
Set xlBook2 = GetObject(myFile2)
xlApp.Windows(myFile2).Visible = True
Set xlSheet2 = xlBook2.Worksheets(myWS3)
xlSheet2.Select
xlSheet2.Copy After:=xlSheet1
xlApp.DisplayAlerts = False
xlSheet3.Delete
xlApp.DisplayAlerts = True
xlBook1.Protect "myCode", True
xlApp.Workbooks.Application.CutCopyMode = False
xlBook1.Worksheets(1).Select
xlApp.Visible = True
xlBook2.Close False
xlBook1.Close True
xlApp.Quit
Set xlSheet1 = Nothing
Set xlSheet2 = Nothing
Set xlSheet3 = Nothing
Set xlBook2 = Nothing
Set xlBook1 = Nothing
Set xlApp = Nothing
End Sub
Do somebody have a solution that makes my VBA code work by only define the workbook (xlBook1) with the code via the getObject function??
It will work opening it officially, but then happens 462 again!
Till next time
Bart Bruins
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|