Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro Open Files
Hello
I am writing a macro that prompts a user to enter two values. These values are need to open certain files on the computer. The two values are two folders the document is located under. I am getting the error "divide by zero" Here's my code: Sub Macro2() Dim filetypenm filetypenm = InputBox("Enter File Name you would like to compare") Dim nm nm = InputBox("Enter Year you would like to compare") Application.GetOpenFilename ("""C:\Documents and Settings\All Users\Documents\Coop Students\Small Package Rates\UPS rates\" & nm \ Air \ " & filetypenm ") Im sure it's just a coding problem that I can't see. Any help would be greatly appreciated. Have been stuck for 2 days! Am making progress though thanks to replies! MSHO |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro Open Files
Try this... I think it is a problem with your quotation marks...
Sub Macro2() Dim filetypenm As String filetypenm = InputBox("Enter File Name you would like to compare") Dim nm As Integer nm = InputBox("Enter Year you would like to compare") Application.GetOpenFilename ("C:\Documents and Settings\AllUsers\Documents\Coop Students\Small Package Rates\UPS rates\" & nm & "\Air\" & filetypenm) End Sub Also make sure you declare your variables with a type otherwise they are variants which are very innefficient. Check out this link on declaring variables. http://www.cpearson.com/excel/variables.htm -- HTH... Jim Thomlinson "MSHO" wrote: Hello I am writing a macro that prompts a user to enter two values. These values are need to open certain files on the computer. The two values are two folders the document is located under. I am getting the error "divide by zero" Here's my code: Sub Macro2() Dim filetypenm filetypenm = InputBox("Enter File Name you would like to compare") Dim nm nm = InputBox("Enter Year you would like to compare") Application.GetOpenFilename ("""C:\Documents and Settings\All Users\Documents\Coop Students\Small Package Rates\UPS rates\" & nm \ Air \ " & filetypenm ") Im sure it's just a coding problem that I can't see. Any help would be greatly appreciated. Have been stuck for 2 days! Am making progress though thanks to replies! MSHO |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro Open Files
Dim filetypenm as string filetypenm = InputBox("Enter File Name you would like to compare") Dim nm as string nm = InputBox("Enter Year you would like to compare") dim sTmp as string stmp = chr(34) & "C:\Documents and Settings\All Users\" stmp = stmp & "Documents\Coop Students\" stmp = stmp & "Small Package Rates\UPS rates\" stmp = stmp & nm & "\ Air \" stmp = stmp & filetypenm & chr(34) Application.GetOpenFilename(stmp) Helmut Weber |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
open files run macro | Excel Discussion (Misc queries) | |||
Open several text files using a macro | Excel Discussion (Misc queries) | |||
Macro for multiple open files | Excel Discussion (Misc queries) | |||
Macro to open *.dat files and save as .txt (comma delimited text files) | Excel Programming | |||
Files won't open after running a macro | Excel Programming |