I am new at using variants and don't know how to do the following.
THIS IS A TEST SCRIPT ONLY.
I have my script open a file that I choose, I then want to capture that window name so that I can close it at the end or do other stuff to that window, obviously the filename changes each time and therefore I wouldn't know what it is each time.
My script would be Dim Win1 as window and once the file is open then it would set the window name as win1 so that I can activate the window at any given time and do stuff in the window.
THIS IS A TEST SCRIPT ONLY.
I have my script open a file that I choose, I then want to capture that window name so that I can close it at the end or do other stuff to that window, obviously the filename changes each time and therefore I wouldn't know what it is each time.
My script would be Dim Win1 as window and once the file is open then it would set the window name as win1 so that I can activate the window at any given time and do stuff in the window.
Code:
Sub test()
[COLOR=purple][B]Dim Win1 As Window[/B][/COLOR]
'
do all sorts of stuff here
' EXAMPLE FOR TEST PURPOSES ONLY
Dim filename As Variant
Dim Filt As String, Title As String
Dim FilterIndex As Integer, Response As Integer
' Set Drive letter
ChDrive "C:\"
' Set to Specified Path\Folder
ChDir "C:\"
' Set File Filter
Filt = "All Files (*.*), *.*"
' Set *.* to Default
FilterIndex = 5
' Set Dialogue Box Caption
Title = "Please select a different File"
' Get FileName
filename = Application.GetOpenFilename(FileFilter:=Filt, _
FilterIndex:=FilterIndex, Title:=Title)
' Exit if Dialogue box cancelled
If filename = False Then
Response = MsgBox("No File was selected", vbOKOnly & vbCritical, "Selection Error")
Exit Sub
End If
' Display Full Path & File Name
'Response = MsgBox("You selected " & FileName, vbInformation, "Proceed")
Workbooks.OpenText filename:=filename, Origin:=xlMSDOS, StartRow _
:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 2), Array(9, 2), Array( _
30, 1), Array(36, 1), Array(45, 1), Array(54, 1), Array(63, 1), Array(73, 1), Array(81, 1), _
Array(96, 1), Array(111, 1)), TrailingMinusNumbers:=True Rows("1:5").Select
Selection.Delete Shift:=xlUp
Columns("A:C").Select
Selection.Copy
[COLOR=purple][B]Set Win1 = ActiveWindow[/B][/COLOR]
Windows("Book3").Activate
Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
[COLOR=purple][B]Windows(Win1).Close[/B][/COLOR]
End Sub