+ Reply to Thread
Results 1 to 2 of 2

Excel opening in safe mode

  1. #1
    Registered User
    Join Date
    02-07-2006
    Posts
    26

    Excel opening in safe mode

    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.


    '
    '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?
    im using windows Xp and microsoft office 2003
    Last edited by redf1re; 05-24-2006 at 11:21 AM.

  2. #2
    Registered User
    Join Date
    02-07-2006
    Posts
    26
    up!
    help me please!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1