ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   button to open a file (https://www.excelbanter.com/excel-programming/306107-re-button-open-file.html)

kolbydayne[_2_]

button to open a file
 
I don't have any programming experience, but I was wondering if ther
was a way to make a button in Excel that you could click and have i
open a file and copy the file into your already open worksheet.

At first I thought it may be as simple as creating a macro, but now
don't think so.

What I would like the button to do is:
1. Open a box that asks you to select the file you want to open.
2. Open the file (a .txt file) and select Delimited with Tabs an
Spaces as delimiters.
3. Copy the contents of the file an place them into the worksheet yo
already have open.

I would love it if the only user intervention was selecting the prope
file to open, and the program did the rest.

Is this that difficult to accomplish? I guess I will go read up o
programming in Excel

--
Message posted from http://www.ExcelForum.com


kolbydayne[_3_]

button to open a file
 
Sorry about the multiple threads, my internet has been acting wierd

--
Message posted from http://www.ExcelForum.com


Dave Peterson[_3_]

button to open a file
 
If you're using xl2k or higher, try recording a macro when you do:
Data|Import external data (may be a different name in different versions).

If you're using xl97 (or higher even), you could use something like:
Option Explicit
Sub testme()

Dim myFileName As Variant
Dim DestCell As Range

myFileName = Application.GetOpenFilename("Text files, *.txt")

If myFileName = False Then
Exit Sub 'user hit cancel
End If

With ActiveSheet
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With

Workbooks.OpenText Filename:=myFileName, _
Origin:=437, StartRow:=1, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, Comma:=False, _
Space:=True

ActiveSheet.UsedRange.Copy _
Destination:=DestCell

ActiveSheet.Parent.Close savechanges:=False


End Sub

"kolbydayne <" wrote:

I don't have any programming experience, but I was wondering if there
was a way to make a button in Excel that you could click and have it
open a file and copy the file into your already open worksheet.

At first I thought it may be as simple as creating a macro, but now I
don't think so.

What I would like the button to do is:
1. Open a box that asks you to select the file you want to open.
2. Open the file (a .txt file) and select Delimited with Tabs and
Spaces as delimiters.
3. Copy the contents of the file an place them into the worksheet you
already have open.

I would love it if the only user intervention was selecting the proper
file to open, and the program did the rest.

Is this that difficult to accomplish? I guess I will go read up on
programming in Excel!

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson



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

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