Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with opening variable filenames


Sub Macro2()
'
' Macro2 Macro
' Macro recorded 2/15/2006 by RADLab
'
' Keyboard Shortcut: Ctrl+m
'
Workbooks.OpenText Filename:= _
"C:\Documents and
Settings\RADLab\Desktop\Tyler\51-100\124shift_focus.diff.mea.51_100.xls"
_
, Origin:=437, StartRow:=1, DataType:=xlDelimited,
TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=False, Space:=False, Other:=False,
FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6,
1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1),
Array(13, 1), Array(14, 1), Array(15 _
, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1),
Array(20, 1), Array(21, 1), _
Array(22, 1), Array(23, 1), Array(24, 1), Array(25, 1),
Array(26, 1), Array(27, 1), Array( _
28, 1), Array(29, 1), Array(30, 1), Array(31, 1), Array(32, 1),
Array(33, 1)), _
TrailingMinusNumbers:=True
Application.Run "shift_focus.diff.mea.51_100.xls!Macro1"
Selection.Copy
Windows("shift_focus.diff.mea.51_100.xls").Activat e
ActiveSheet.Paste
End Sub

Instead of 124 I want the value to be equal to the value I select but I
don't know how to insert a variable into a string.


--
MacroProblems
------------------------------------------------------------------------
MacroProblems's Profile: http://www.excelforum.com/member.php...o&userid=31596
View this thread: http://www.excelforum.com/showthread...hreadid=512883

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Help with opening variable filenames

Splice together three strings:


replace:
"C:\Documents and
Settings\RADLab\Desktop\Tyler\51-100\124shift_focus.diff.mea.51_100.xls"

with

"C:\Documents and Settings\RADLab\Desktop\Tyler\51-100\" & s &
"shift_focus.diff.mea.51_100.xls"

where you have already
Dim s as String
s="124"

or any other string you like.
--
Gary's Student


"MacroProblems" wrote:


Sub Macro2()
'
' Macro2 Macro
' Macro recorded 2/15/2006 by RADLab
'
' Keyboard Shortcut: Ctrl+m
'
Workbooks.OpenText Filename:= _
"C:\Documents and
Settings\RADLab\Desktop\Tyler\51-100\124shift_focus.diff.mea.51_100.xls"
_
, Origin:=437, StartRow:=1, DataType:=xlDelimited,
TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=False, Space:=False, Other:=False,
FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6,
1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1),
Array(13, 1), Array(14, 1), Array(15 _
, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1),
Array(20, 1), Array(21, 1), _
Array(22, 1), Array(23, 1), Array(24, 1), Array(25, 1),
Array(26, 1), Array(27, 1), Array( _
28, 1), Array(29, 1), Array(30, 1), Array(31, 1), Array(32, 1),
Array(33, 1)), _
TrailingMinusNumbers:=True
Application.Run "shift_focus.diff.mea.51_100.xls!Macro1"
Selection.Copy
Windows("shift_focus.diff.mea.51_100.xls").Activat e
ActiveSheet.Paste
End Sub

Instead of 124 I want the value to be equal to the value I select but I
don't know how to insert a variable into a string.


--
MacroProblems
------------------------------------------------------------------------
MacroProblems's Profile: http://www.excelforum.com/member.php...o&userid=31596
View this thread: http://www.excelforum.com/showthread...hreadid=512883


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help with opening variable filenames

I don't think I'd use .xls with a text file, but...

dim myFilename as variant
myfilename = application.getopenfilename("Text files, *.txt")
if myfilename = false then
exit sub 'user hit cancel
end if

Workbooks.OpenText Filename:= myfilename, .....

This actually lets you pick the file you want to import.

MacroProblems wrote:

Sub Macro2()
'
' Macro2 Macro
' Macro recorded 2/15/2006 by RADLab
'
' Keyboard Shortcut: Ctrl+m
'
Workbooks.OpenText Filename:= _
"C:\Documents and
Settings\RADLab\Desktop\Tyler\51-100\124shift_focus.diff.mea.51_100.xls"
_
, Origin:=437, StartRow:=1, DataType:=xlDelimited,
TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=False, Space:=False, Other:=False,
FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6,
1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1),
Array(13, 1), Array(14, 1), Array(15 _
, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1),
Array(20, 1), Array(21, 1), _
Array(22, 1), Array(23, 1), Array(24, 1), Array(25, 1),
Array(26, 1), Array(27, 1), Array( _
28, 1), Array(29, 1), Array(30, 1), Array(31, 1), Array(32, 1),
Array(33, 1)), _
TrailingMinusNumbers:=True
Application.Run "shift_focus.diff.mea.51_100.xls!Macro1"
Selection.Copy
Windows("shift_focus.diff.mea.51_100.xls").Activat e
ActiveSheet.Paste
End Sub

Instead of 124 I want the value to be equal to the value I select but I
don't know how to insert a variable into a string.

--
MacroProblems
------------------------------------------------------------------------
MacroProblems's Profile: http://www.excelforum.com/member.php...o&userid=31596
View this thread: http://www.excelforum.com/showthread...hreadid=512883


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
APS APS is offline
external usenet poster
 
Posts: 5
Default Help with opening variable filenames

Try something like

sNum = "124"

Workbooks.OpenText Filename:= _
"C:\Documents and
Settings\RADLab\Desktop\Tyler\51-100\" & sNum &
"shift_focus.diff.mea.51_100.xls"

If you want the number 124 to be entered by a user try;

sNum = InputBox("Enter number")

_


"MacroProblems" wrote:


Sub Macro2()
'
' Macro2 Macro
' Macro recorded 2/15/2006 by RADLab
'
' Keyboard Shortcut: Ctrl+m
'
Workbooks.OpenText Filename:= _
"C:\Documents and
Settings\RADLab\Desktop\Tyler\51-100\124shift_focus.diff.mea.51_100.xls"
_
, Origin:=437, StartRow:=1, DataType:=xlDelimited,
TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=False, Space:=False, Other:=False,
FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6,
1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1),
Array(13, 1), Array(14, 1), Array(15 _
, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1),
Array(20, 1), Array(21, 1), _
Array(22, 1), Array(23, 1), Array(24, 1), Array(25, 1),
Array(26, 1), Array(27, 1), Array( _
28, 1), Array(29, 1), Array(30, 1), Array(31, 1), Array(32, 1),
Array(33, 1)), _
TrailingMinusNumbers:=True
Application.Run "shift_focus.diff.mea.51_100.xls!Macro1"
Selection.Copy
Windows("shift_focus.diff.mea.51_100.xls").Activat e
ActiveSheet.Paste
End Sub

Instead of 124 I want the value to be equal to the value I select but I
don't know how to insert a variable into a string.


--
MacroProblems
------------------------------------------------------------------------
MacroProblems's Profile: http://www.excelforum.com/member.php...o&userid=31596
View this thread: http://www.excelforum.com/showthread...hreadid=512883


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening worbooks with a variable file name. ibbm Excel Programming 5 January 5th 06 02:58 AM
Opening Variable File Names simoncohen[_7_] Excel Programming 1 November 16th 04 01:49 PM
excel VBA problem - setting workbook as variable & opening/re-opening safe Excel Programming 1 August 20th 04 12:22 AM
Help in opening powerpoint file variable from excel Mithi_M Excel Programming 1 August 1st 04 04:33 PM
Variable Filenames Paul Kendall Excel Programming 2 October 13th 03 03:30 PM


All times are GMT +1. The time now is 11:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"