Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default Setting a string variable as the file name

I am trying to set a string variable as the file name for a workbook
so that I can open another workbook and copy sheets into the 1st
workbook. Here is what I have so far:

Sub MoveSheets()

Dim BkName As String
Dim NumSht As Integer
Dim BegSht As Integer
Dim FileNum As String
Dim ActiveWKBK As String

'Starts with third sheet - replace with index number of starting
sheet.
BegSht = 3
'Moves 7 sheets - replace with number of sheets to move.
NumSht = 7
BkName = ActiveWorkbook.Name

'Sets the active directory
ChDir "C:\Documents and Settings\hx27484\Desktop\Work Books"

'User input the Assembly Number to get workbook
On Error Resume Next
FileNum = InputBox("Enter Assembly Number")
If Err.Number = 0 Then
ChDir "C:\Documents and Settings\hx27484\Desktop\Work Books"
Workbooks.Open Filename:=FileNum
If Err.Number = 0 Then
'file opened ok

For x = 1 To NumSht
'Moves third sheet in source to front of designated
workbook.
Workbooks(FileNum).Sheets(BegSht).Move _
Befo=Workbooks(BkName).Sheets(4)
'In each loop, the next sheet in line becomes indexed as
number 3.

Next

'Response if the file could not open
Else
MsgBox "Could Not Open File, Try Again"
End If
Else
MsgBox "Invalid File Number"
End If

End Sub



However in the code line below the file names are usually entered as
Workbooks("File Name.xls"):
Workbooks(FileNum).Sheets(BegSht).Move _
Befo=Workbooks(BkName).Sheets(4)

I would like to use a variable here because the workbook names wont be
the same. I am all out of ideas on how to make this work, any ideas???

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 149
Default Setting a string variable as the file name

Not 100% sure what you're asking but I think you want:
FileNum = InputBox("Enter Assembly Number")
FileNum = FileNum & ".xls"

HTH,

wrote in message
oups.com...
I am trying to set a string variable as the file name for a workbook
so that I can open another workbook and copy sheets into the 1st
workbook. Here is what I have so far:

Sub MoveSheets()

Dim BkName As String
Dim NumSht As Integer
Dim BegSht As Integer
Dim FileNum As String
Dim ActiveWKBK As String

'Starts with third sheet - replace with index number of starting
sheet.
BegSht = 3
'Moves 7 sheets - replace with number of sheets to move.
NumSht = 7
BkName = ActiveWorkbook.Name

'Sets the active directory
ChDir "C:\Documents and Settings\hx27484\Desktop\Work Books"

'User input the Assembly Number to get workbook
On Error Resume Next
FileNum = InputBox("Enter Assembly Number")
If Err.Number = 0 Then
ChDir "C:\Documents and Settings\hx27484\Desktop\Work Books"
Workbooks.Open Filename:=FileNum
If Err.Number = 0 Then
'file opened ok

For x = 1 To NumSht
'Moves third sheet in source to front of designated
workbook.
Workbooks(FileNum).Sheets(BegSht).Move _
Befo=Workbooks(BkName).Sheets(4)
'In each loop, the next sheet in line becomes indexed as
number 3.

Next

'Response if the file could not open
Else
MsgBox "Could Not Open File, Try Again"
End If
Else
MsgBox "Invalid File Number"
End If

End Sub



However in the code line below the file names are usually entered as
Workbooks("File Name.xls"):
Workbooks(FileNum).Sheets(BegSht).Move _
Befo=Workbooks(BkName).Sheets(4)

I would like to use a variable here because the workbook names wont be
the same. I am all out of ideas on how to make this work, any ideas???



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
Setting up variable summary sheet. shakey1181 Excel Discussion (Misc queries) 4 August 18th 06 01:37 PM
Variable in string DevinC Excel Discussion (Misc queries) 5 January 26th 06 08:59 PM
Userform button setting variable from formula teepee Excel Discussion (Misc queries) 4 January 4th 06 06:59 PM
Userform button setting variable from formula teepee Excel Discussion (Misc queries) 0 January 3rd 06 08:26 PM
Setting a variable cell address Hugh Jago Excel Discussion (Misc queries) 3 January 5th 05 03:45 PM


All times are GMT +1. The time now is 09:42 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"