Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default (Disable macro's while) using the GetObject

Hi all,

I have a piece of code which opens an excel file ("Optellen.xls") (this file
has code in it, also in the Workbook_Open). When I run the code which opens
Optellen.xls, the debugger debugs in Optellen.xls???. How is this possible,
does it run the VB code in Opt...xls as well???

QUESTION: How can I make sure, that my code just opens Optellen.xls, but
(probably thats the problem) without enabling it's macro's?
Here's my code:

Public Sub BatchNames()
'
Dim Wrb As Excel.Workbook
'
Set Wrb = GetObject("C:\Documents and
Settings\Max\Desktop\Rekenprogramma\Optellen.xls")
'
Wrb.Unprotect (my password)
'
filepath = "C:\Documents and Settings\Max\Desktop\temp"
Filename = "namen.xls"
sheetname = "Sheet1"

Wrb.Sheets("Leraar").Range("A2:A18").ClearContents
'
For n = 2 To 36
Wrb.Sheets("Leraar").Cells(n, 2).Value = 1
Wrb.Sheets("Leraar").Cells(n, 4).Value = 0
Next n
'
For n = 2 To 15
Strg = "'" & filepath & "\[" & Filename & "]" _
& sheetname & "'!" & "r" & n - 1 & "c1"
MsgBox "Strg = " & Strg 'just a test
Wrb.Sheets("Leraar").Cells(n, 1).Value = ExecuteExcel4Macro(Strg)
Next n
'
Wrb.Save
'
Wrb.Close
'
Set Wrb = Nothing
'
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default (Disable macro's while) using the GetObject

Why are you using getobject to open an excel file. Just use workbooks.Open
and disable events before opening.

--
Regards,
Tom Ogilvy

"Max Potters" wrote in message
...
Hi all,

I have a piece of code which opens an excel file ("Optellen.xls") (this

file
has code in it, also in the Workbook_Open). When I run the code which

opens
Optellen.xls, the debugger debugs in Optellen.xls???. How is this

possible,
does it run the VB code in Opt...xls as well???

QUESTION: How can I make sure, that my code just opens Optellen.xls, but
(probably thats the problem) without enabling it's macro's?
Here's my code:

Public Sub BatchNames()
'
Dim Wrb As Excel.Workbook
'
Set Wrb = GetObject("C:\Documents and
Settings\Max\Desktop\Rekenprogramma\Optellen.xls")
'
Wrb.Unprotect (my password)
'
filepath = "C:\Documents and Settings\Max\Desktop\temp"
Filename = "namen.xls"
sheetname = "Sheet1"

Wrb.Sheets("Leraar").Range("A2:A18").ClearContents
'
For n = 2 To 36
Wrb.Sheets("Leraar").Cells(n, 2).Value = 1
Wrb.Sheets("Leraar").Cells(n, 4).Value = 0
Next n
'
For n = 2 To 15
Strg = "'" & filepath & "\[" & Filename & "]" _
& sheetname & "'!" & "r" & n - 1 & "c1"
MsgBox "Strg = " & Strg 'just a test
Wrb.Sheets("Leraar").Cells(n, 1).Value = ExecuteExcel4Macro(Strg)
Next n
'
Wrb.Save
'
Wrb.Close
'
Set Wrb = Nothing
'
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default (Disable macro's while) using the GetObject

Tom, I considered that. But can I open a file with a huge path like I have.

For example: workbooks.Open("C:\Documents and
Settings\max\Desktop\namen.xls")???

And, second of all, how do I disable it's events? I don't want to see the
Enable/Disable macro message when it starts, i just want to disable them

how do I do this?

Thanks (already)
Max
"Tom Ogilvy" wrote in message
...
Why are you using getobject to open an excel file. Just use

workbooks.Open
and disable events before opening.

--
Regards,
Tom Ogilvy

"Max Potters" wrote in message
...
Hi all,

I have a piece of code which opens an excel file ("Optellen.xls") (this

file
has code in it, also in the Workbook_Open). When I run the code which

opens
Optellen.xls, the debugger debugs in Optellen.xls???. How is this

possible,
does it run the VB code in Opt...xls as well???

QUESTION: How can I make sure, that my code just opens Optellen.xls, but
(probably thats the problem) without enabling it's macro's?
Here's my code:

Public Sub BatchNames()
'
Dim Wrb As Excel.Workbook
'
Set Wrb = GetObject("C:\Documents and
Settings\Max\Desktop\Rekenprogramma\Optellen.xls")
'
Wrb.Unprotect (my password)
'
filepath = "C:\Documents and Settings\Max\Desktop\temp"
Filename = "namen.xls"
sheetname = "Sheet1"

Wrb.Sheets("Leraar").Range("A2:A18").ClearContents
'
For n = 2 To 36
Wrb.Sheets("Leraar").Cells(n, 2).Value = 1
Wrb.Sheets("Leraar").Cells(n, 4).Value = 0
Next n
'
For n = 2 To 15
Strg = "'" & filepath & "\[" & Filename & "]" _
& sheetname & "'!" & "r" & n - 1 & "c1"
MsgBox "Strg = " & Strg 'just a test
Wrb.Sheets("Leraar").Cells(n, 1).Value = ExecuteExcel4Macro(Strg)
Next n
'
Wrb.Save
'
Wrb.Close
'
Set Wrb = Nothing
'
End Sub






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default (Disable macro's while) using the GetObject

Application.EnableEvents = False
set wkbk = workbooks.Open( _
"C:\Documents and Settings\max\Desktop\namen.xls")
Application.EnableEvents = True
msgbox wkbk.Name & " has been opened"

this doesn't disable macros, but it keeps the workbook_open event from
running which is usually what is desired.

--
Regards,
Tom Ogilvy



"Max Potters" wrote in message
...
Tom, I considered that. But can I open a file with a huge path like I

have.

For example: workbooks.Open("C:\Documents and
Settings\max\Desktop\namen.xls")???

And, second of all, how do I disable it's events? I don't want to see the
Enable/Disable macro message when it starts, i just want to disable them

how do I do this?

Thanks (already)
Max
"Tom Ogilvy" wrote in message
...
Why are you using getobject to open an excel file. Just use

workbooks.Open
and disable events before opening.

--
Regards,
Tom Ogilvy

"Max Potters" wrote in message
...
Hi all,

I have a piece of code which opens an excel file ("Optellen.xls")

(this
file
has code in it, also in the Workbook_Open). When I run the code which

opens
Optellen.xls, the debugger debugs in Optellen.xls???. How is this

possible,
does it run the VB code in Opt...xls as well???

QUESTION: How can I make sure, that my code just opens Optellen.xls,

but
(probably thats the problem) without enabling it's macro's?
Here's my code:

Public Sub BatchNames()
'
Dim Wrb As Excel.Workbook
'
Set Wrb = GetObject("C:\Documents and
Settings\Max\Desktop\Rekenprogramma\Optellen.xls")
'
Wrb.Unprotect (my password)
'
filepath = "C:\Documents and Settings\Max\Desktop\temp"
Filename = "namen.xls"
sheetname = "Sheet1"

Wrb.Sheets("Leraar").Range("A2:A18").ClearContents
'
For n = 2 To 36
Wrb.Sheets("Leraar").Cells(n, 2).Value = 1
Wrb.Sheets("Leraar").Cells(n, 4).Value = 0
Next n
'
For n = 2 To 15
Strg = "'" & filepath & "\[" & Filename & "]" _
& sheetname & "'!" & "r" & n - 1 & "c1"
MsgBox "Strg = " & Strg 'just a test
Wrb.Sheets("Leraar").Cells(n, 1).Value = ExecuteExcel4Macro(Strg)
Next n
'
Wrb.Save
'
Wrb.Close
'
Set Wrb = Nothing
'
End Sub








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default (Disable macro's while) using the GetObject

Thank you Tom
"Tom Ogilvy" wrote in message
...
Application.EnableEvents = False
set wkbk = workbooks.Open( _
"C:\Documents and Settings\max\Desktop\namen.xls")
Application.EnableEvents = True
msgbox wkbk.Name & " has been opened"

this doesn't disable macros, but it keeps the workbook_open event from
running which is usually what is desired.

--
Regards,
Tom Ogilvy



"Max Potters" wrote in message
...
Tom, I considered that. But can I open a file with a huge path like I

have.

For example: workbooks.Open("C:\Documents and
Settings\max\Desktop\namen.xls")???

And, second of all, how do I disable it's events? I don't want to see

the
Enable/Disable macro message when it starts, i just want to disable them

how do I do this?

Thanks (already)
Max
"Tom Ogilvy" wrote in message
...
Why are you using getobject to open an excel file. Just use

workbooks.Open
and disable events before opening.

--
Regards,
Tom Ogilvy

"Max Potters" wrote in message
...
Hi all,

I have a piece of code which opens an excel file ("Optellen.xls")

(this
file
has code in it, also in the Workbook_Open). When I run the code

which
opens
Optellen.xls, the debugger debugs in Optellen.xls???. How is this
possible,
does it run the VB code in Opt...xls as well???

QUESTION: How can I make sure, that my code just opens Optellen.xls,

but
(probably thats the problem) without enabling it's macro's?
Here's my code:

Public Sub BatchNames()
'
Dim Wrb As Excel.Workbook
'
Set Wrb = GetObject("C:\Documents and
Settings\Max\Desktop\Rekenprogramma\Optellen.xls")
'
Wrb.Unprotect (my password)
'
filepath = "C:\Documents and Settings\Max\Desktop\temp"
Filename = "namen.xls"
sheetname = "Sheet1"

Wrb.Sheets("Leraar").Range("A2:A18").ClearContents
'
For n = 2 To 36
Wrb.Sheets("Leraar").Cells(n, 2).Value = 1
Wrb.Sheets("Leraar").Cells(n, 4).Value = 0
Next n
'
For n = 2 To 15
Strg = "'" & filepath & "\[" & Filename & "]" _
& sheetname & "'!" & "r" & n - 1 & "c1"
MsgBox "Strg = " & Strg 'just a test
Wrb.Sheets("Leraar").Cells(n, 1).Value = ExecuteExcel4Macro(Strg)
Next n
'
Wrb.Save
'
Wrb.Close
'
Set Wrb = Nothing
'
End Sub










Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically disable macro's on new doc Sarah (OGI) Excel Discussion (Misc queries) 12 August 17th 07 02:19 AM
don't let the user disable macro's in Excel Filip De Backer Excel Programming 1 April 9th 04 12:39 PM
Disable AutoOpen macro's Michael Beckinsale Excel Programming 1 October 16th 03 01:48 PM
enable/disable macro's dialog? Trevor Shuttleworth Excel Programming 0 August 19th 03 10:14 PM


All times are GMT +1. The time now is 01:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"