Excel opening in safe mode

R

redf1re

hello everybody!

Here is my problem: im trying to open a .xls by command line, and this
..xls has an Auto_Open macro (the macro is in the end of the post) and
the macro security is turned low. The problem is that when i try to
open it by command line excel opens in safe mode (i presume its called
safe mode, because it´s what is written besides the name of the .xls on
the top of excel) and my macro security is turned high, which causes
Auto_Open not to work. Well, if i try to open the .xls by double
clicking it, the macro security does not change!
I dont know what to do!!!
this is how i call the .xls from the command line:
"excel.exe" /testing "c:\test.xls"

and this is the macro:


Option Base 1
'---API Declare---
Private Declare Function GetCommandLine Lib "kernel32" Alias
"GetCommandLineA" () As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal
lpString As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"
(pDst As Any, pSrc As Any, ByVal ByteLen As Long)

'Purpose : Returns the command line
'Inputs : N/A
'Outputs : The command line used to initate Excel
'Author : Andrew Baker (www.vbusers.com)
'Notes : To return meaningful command line information you must
open the workbook
' by shelling it as a parameter for Excel.exe, eg. using
the following syntax:
' "D:\Program Files\Microsoft Office\Office\EXCEL.EXE"
/MyCommand "d:\command line.xls"
' i.e. The path to Excel, then the command and finally
the workbook.
' Note the paths are encapsulated in double quotes.

' NT USERS: YOU MUST OPEN EXCEL BY SHELLING IT USING THE
SYNTAX GIVEN ABOVE.
' IF A WORKBOOK IS OPENED BY DOUBLE CLICKING IT IN
EXPLORER THIS API CALL WILL CAUSE A GPF.
'
'Revisions :

Function CommandLine() As String
Dim lRetStr As Long, lLen As Long
Static ssCmd As String

If Len(ssCmd) = 0 Then
'Get a pointer to a string, which contains the command line
lRetStr = GetCommandLine
'Get the length of that string
lLen = lstrlen(lRetStr)
If lLen > 0 Then
'Create a Buffer
ssCmd = Space$(lLen)
'Copy to the Buffer
CopyMemory ByVal ssCmd, ByVal lRetStr, lLen
End If
End If
CommandLine = ssCmd
End Function


Sub Auto_Open()

Dim CmdLine As String 'command-line string
Dim Args() As String 'array for storing the parameters
Dim ArgCount As Integer 'number of parameters
Dim Pos1 As Integer, Pos2 As Integer

CmdLine = CommandLine
On Error Resume Next 'for the wksht-function "Search"

Pos1 = WorksheetFunction.Search("/", CmdLine, 1) + 1 'search "/"
Pos2 = WorksheetFunction.Search("/", CmdLine, Pos1) + 1 'MCU
Worksheets(1).Range("A1").Value = Mid(CmdLine, Pos1, Pos2 - Pos1 - 1)
Pos1 = Pos2
Pos2 = WorksheetFunction.Search("/", CmdLine, Pos1) + 1 'Livro
Worksheets(1).Range("B4").Value = Mid(CmdLine, Pos1, Pos2 - Pos1 - 1)

End Sub



anyone could help me please?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top