+ Reply to Thread
Results 1 to 5 of 5

Opening a webpage with VBA

  1. #1
    Forum Contributor
    Join Date
    09-02-2005
    Posts
    146

    Opening a webpage with VBA

    Originally Posted by Leith Ross
    Hello Gabor,

    Place this macro in a Standard VBA Module in your project. When you call the macro, the full folder path follows the macro.
    Calling Example

    Code:
    Please Login or Register  to view this content.
    Code:

    Please Login or Register  to view this content.
    End SubSincerely,
    Leith Ross


    I'm trying to use this to work with a SharePoint website, but nothing is happening. The code just seems to skip this line. No error messages or anything. I'm using it like this:



    Please Login or Register  to view this content.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Wilro85,

    This macro has error checking added to it. This will display an error if one occurs.
    Please Login or Register  to view this content.
    Suncerely,
    Leith Ross

  3. #3
    Forum Contributor
    Join Date
    09-02-2005
    Posts
    146
    Yep, that worked.

    Could you explain how the "ShellExecute" line is working? I haven't been able to find anything about it in VBA's help file.

    What do the "0&", zeros, and "1&" do?

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Wilro85,

    You won't find anything about it in the VBA help files because it is an API (Applications Programming Interface) function. These can be run from in VBA by using the Declare keyword before either Sub or Function followed by the API entry point name, which is case sensitive, the Library the call can be found in, and the required Arguments.

    The ShellExecute function takes 6 parameters.
    1) hWnd - (standard API abbreviation for Window Handle). A handle to the owner window used for displaying a user interface (UI) or error messages. This value can be 0 (zero) if the operation is not associated with a window.

    2) lpOperation - A pointer to a null-terminated string, referred to in this case as a verb, that specifies the action to be performed. The set of available verbs depends on the particular file or folder. Generally, the actions available from an object's shortcut menu are available verbs. The following verbs are commonly used:
    EDIT Launches an editor and opens the document for editing. If lpFile is not a document file, the function will fail.
    EXPLORE Explores a folder specified by lpFile.
    FIND Initiates a search beginning in the directory specified by lpDirectory.
    OPEN Opens the item specified by the lpFile parameter. The item can be a file or folder.
    PRINT Prints the file specified by lpFile. If lpFile is not a document file, the function fails.
    0 (zero) In systems prior to Microsoft Windows 2000, the default verb is used if it is valid and available in the registry. If not, the "open" verb is used.
    3) lpFile - A pointer to a null-terminated string that specifies the file or object on which to execute the specified verb. Note that not all verbs are supported on all objects. For example, not all document types support the "print" verb. If a relative path is used for the lpDirectory parameter do not use a relative path forlpFile.

    4) lpParameters - If lpFile specifies an executable file, this parameter is a pointer to a null-terminated string that specifies the parameters to be passed to the application. The format of this string is determined by the verb that is to be invoked. If lpFile specifies a document file, lpParameters should be 0 (zero).

    5) lpDirectory - A pointer to a null-terminated string that specifies the default (working) directory for the action. If this value is 0 (zero), the current working directory is used. If a relative path is provided at lpFile, do not use a relative path for lpDirectory.

    6) nShowCmd - The flags that specify how an application is to be displayed when it is opened. If lpFile specifies a document file, the flag is simply passed to the associated application. It is up to the application to decide how to handle it.
    Here is a list of the show command constants (names and values). These constants are defined in the API, but you must either use their values or code them as constants in VBA.
    SW_HIDE = 0&
    Hides the window and activates another window.
    SW_MAXIMIZE = 3&
    Maximizes the specified window.
    SW_MINIMIZE = 6&
    Minimizes the specified window and activates the next top-level window in the z-order.
    SW_RESTORE = 9&
    Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.
    SW_SHOW = 5&
    Activates the window and displays it in its current size and position.
    SW_SHOWDEFAULT = 10&
    Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. An application should call ShowWindow with this flag to set the initial show state of its main window.
    SW_SHOWMAXIMIZED = 3&
    Activates the window and displays it as a maximized window.
    SW_SHOWMINIMIZED = 2&
    Activates the window and displays it as a minimized window.
    SW_SHOWMINNOACTIVE = 7&
    Displays the window as a minimized window. The active window remains active.
    SW_SHOWNA = 8&
    Displays the window in its current state. The active window remains active.
    SW_SHOWNOACTIVATE = 4&
    Displays a window in its most recent size and position. The active window remains active.
    SW_SHOWNORMAL = 1&
    Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
    Sincerely,
    Leith Ross

  5. #5
    Forum Contributor
    Join Date
    09-02-2005
    Posts
    146
    Ok, so I've been using the above code with great success. Now, is it possible to modify this code to close folders (or other office documents)?

    In other words: Let's say I use that code to open a word document. Is there a way to use a similar code to close the document when the user is done?

+ 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