ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   I need Code to open DBF file in an excel worksheet (https://www.excelbanter.com/excel-programming/328415-i-need-code-open-dbf-file-excel-worksheet.html)

Jason Ward

I need Code to open DBF file in an excel worksheet
 


Hi All,

Here is what I am trying to do. I have a button called "Open" which is
used to bring up the file open window code as follows: myfilepath =
myapp.GetOpenFilename(",*.dbf", , "Open File")

My questions is; is there a way that I can now add some code here so
that the file i choose opens in Worksheet1. Along the same lines as:
Destination:=Worksheets("Sheet1").Range("A1")

I cannot seem to get it working any ideas would be welcomed.

Jason

*** Sent via Developersdex http://www.developersdex.com ***

William[_2_]

I need Code to open DBF file in an excel worksheet
 
Hi Jason

Sub test()
Dim s As String, v As Variant
Dim wb As Workbook, ws As Worksheet
s = "C:\My Folder\My Sub Folder"
ChDrive s
ChDir s
v = Application.GetOpenFilename("(*.dbf), *.dbf")
If v = False Then Exit Sub
Application.EnableEvents = False
Application.ScreenUpdating = False
Set wb = Workbooks.Open(Filename:=v)
Set ws = wb.ActiveSheet
ws.Cells.Copy ThisWorkbook.Sheets("Sheet1").Range("A1")
wb.Close savechanges:=False
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

--

XL2003
Regards

William



"Jason Ward" wrote in message
...


Hi All,

Here is what I am trying to do. I have a button called "Open" which is
used to bring up the file open window code as follows: myfilepath =
myapp.GetOpenFilename(",*.dbf", , "Open File")

My questions is; is there a way that I can now add some code here so
that the file i choose opens in Worksheet1. Along the same lines as:
Destination:=Worksheets("Sheet1").Range("A1")

I cannot seem to get it working any ideas would be welcomed.

Jason

*** Sent via Developersdex
http://www.developersdex.com ***



Jason Ward

I need Code to open DBF file in an excel worksheet
 

Hi William,

Thanks for the suggestion. It isn't work correctly though. It will open
the .dbf file but it gives a runtime error, and the .dbf file still
opens in its own excel window not into worksheet1. I modified s = "C:\My
Folder\My Sub Folder" to s = "d:\" where the file is stored. Should I be
pulling it of the hard drive instead of a cd rom maybe?

Thanks Again,

Jason


*** Sent via Developersdex http://www.developersdex.com ***

William[_2_]

I need Code to open DBF file in an excel worksheet
 
Jason

Its always better to work from the hard drive rather then a CD (you can
always copy the file back to the CD later).

At what line of code do you get the run time error - (what is highlighted in
VB).
--

XL2003
Regards

William



"Jason Ward" wrote in message
...

Hi William,

Thanks for the suggestion. It isn't work correctly though. It will open
the .dbf file but it gives a runtime error, and the .dbf file still
opens in its own excel window not into worksheet1. I modified s = "C:\My
Folder\My Sub Folder" to s = "d:\" where the file is stored. Should I be
pulling it of the hard drive instead of a cd rom maybe?

Thanks Again,

Jason


*** Sent via Developersdex
http://www.developersdex.com ***




All times are GMT +1. The time now is 05:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com