View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Allow user input into VBA Module?

Dim bk as Workbook
Dim sName as String
Dim sName1 as String
sName = Inputbox("Please Enter the file name of the open data base" & _
vbNewLine & " ex: Export.dbf", Default:="Export.dbf")
if sname = "" then exit sub
On Error Resume Next
if lcase(right(sname,3)) < "dbf" then
sName = sName & ".dbf"
end if
set bk = workbooks(sName)
On Error goto 0
if bk is nothing then
Msgbox sName & " isn't currently open, please open it"
sName1 = Application.GetOpenfilename()
if sName1 < "False" then
set bk = workbooks.Open(sName1)
else
exit sub
end if
end if
bk.worksheets(1).UsedRange.Copy Destination:= _
Workbooks(Abook).Worksheets(Asheet) _
.Range("A1")


--
Regards,
Tom Ogilvy



"Joel Mills" wrote in message
...
I would like to be able to allow a user input the selected DBF file name
into the code instead of instructing them to name the DBF file as export.
Below is the code I currently use to copy the data into my worksheet.

Also
there would need to be an error message that let them know that the file
wasn't opened if they either forget to open the file before running the
macro or misspell the name.

Any help would be appreciated.

Joel



Sub CopyData()

Worksheets("Export").Activate
'
Dim Asheet, Abook As String
Abook = ActiveWorkbook.Name
Asheet = ActiveSheet.Name

'This copies the data from the dbf file into the Worksheet Titled "Export"
Windows("Export.DBF").Activate
Range("A1").Select
ActiveCell.CurrentRegion.Select
Selection.Copy
Windows(Abook).Activate
Worksheets(Asheet).Activate
Range("A1").Select
ActiveSheet.Paste
Worksheets("Instructions").Activate
End Sub