# Access 2K: Use Macro To Open URL



## keith10456 (Mar 17, 2004)

*I'm trying to use a macro to open a URL.

For example, while in design view, how would I design the macro to open this Forum?*

http://forums.techguy.org/forumdisplay.php?f=16


----------



## Rockn (Jul 29, 2001)

Use VBA and assign this routine to the onClick event. Macros are very limited.
You could also write it as a module and call it from a Macro if you want.

strPath = "URL Name"

Application.FollowHyperlink strPath, , NewWindow:=True


----------



## keith10456 (Mar 17, 2004)

Hope I don't sound too stupid but I'm new to VBA... How would I go about doing your recommendation?


----------



## Rockn (Jul 29, 2001)

What do you want to use it for first off, from a form or what? VBA = Visual Basic for Applications


----------



## keith10456 (Mar 17, 2004)

From a form and from a menu...


----------



## Rockn (Jul 29, 2001)

I am still missing what you are trying to do. Do you want a text box with a URL in it and a button to process that URL? You can make hyperlinks work by setting the datatype in the table to "hyperlink" and it will automatically assume it should open a web page.


----------



## keith10456 (Mar 17, 2004)

In my db I have a macro that exports data to a spreadsheet. After the data is exported, I would like the macro to open the spreadsheet.

I know how to add the URL to the form (insert hyperlink)... However, I would like the spreadsheet to open as part of the macro (or vb as you mentioned above).


----------



## Rollin_Again (Sep 4, 2003)

Here is one way using late binding. It's preferable to use early binding and set reference to the Excel library.


```
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.Open ("C:\Test.xls")    'Change to your workbook path
```
Rollin


----------



## keith10456 (Mar 17, 2004)

Where do I put that code? Also, what is "late/early binding"?

Sorry for asking stupid questions!


----------



## Rollin_Again (Sep 4, 2003)

You can also use a *SHELL* statement to opent the specified file. Using Shell will open the file only and will not allow you to manipulate or modify the file like you can using VBA.


```
Shell "C:\[i]Your Full Path to Excel.exe[/i] C:\[i]Your Full Path to Your Excel File[/i]"
```
Rollin


----------



## Rollin_Again (Sep 4, 2003)

Take the code I provided to you and in Access press *ALT + F11* to to bring up your VB editor.

Next, insert a module by selecting INSERT--> MODULE. Once the blank module is inserted, copy and paste the code I provided into the blank module and re-save the database.

You can now call the macro from within Access or associate the code with a button click if you prefer.

To associate the code with a button click, just right click your button on your form (in design view) and choose "Build Event" and paste the code I gave you in the module.

Rollin


----------



## keith10456 (Mar 17, 2004)

Was your last message in reference to the first code you gave me or the second?


----------



## Rollin_Again (Sep 4, 2003)

How do you want the code to execute? Are you going to click a button on your form or will some other event kick the code off? 


Rollin


----------



## keith10456 (Mar 17, 2004)

Click a button...


----------



## Rollin_Again (Sep 4, 2003)

To associate the code with a button click, just right click your button on your form (in design view) and choose "Build Event" and paste the code I gave you in the module.


----------

