Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Closing file with Macro

Hello

I do have a macro (see below) i'm able to open a TXT file. But how can i
close the file when the macro is over

Thanks a lot for your help

Louis



Public Sub OpenFile()
Dim strText As String
Dim strFile As String

strText = Application.InputBox("dernier 4 chiffres")

strFile = "C:\Program Files\TMI Software\ValiVacq 4.3.2\119452" & _
strText & " inst verpackt kantonsspital nidwalden app 95005v.txt"

If Dir(strFile) = "" Then Exit Sub

Workbooks.OpenText Filename:=strFile _
, Origin:=932, 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)), _
TrailingMinusNumbers:=True
Cells.Select
With selection.Font
.Name = "Arial"
.Size = 8
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
With selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("C1").Select
Range(selection, selection.End(xlToRight)).Select
Range(selection, selection.End(xlDown)).Select
selection.Copy
Windows("Feuille verticale.xls").Activate
Range("A1").Select
ActiveSheet.Paste
Worksheets("Messwerte Sterilisationzyklus").Activate
Range("A1").Select

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Closing file with Macro


"Louis" wrote in message
...
Hello

I do have a macro (see below) i'm able to open a TXT file. But how can i
close the file when the macro is over

Thanks a lot for your help

Louis



Public Sub OpenFile()
Dim strText As String
Dim strFile As String

strText = Application.InputBox("dernier 4 chiffres")

strFile = "C:\Program Files\TMI Software\ValiVacq 4.3.2\119452" & _
strText & " inst verpackt kantonsspital nidwalden app
95005v.txt"

If Dir(strFile) = "" Then Exit Sub

Workbooks.OpenText Filename:=strFile _
, Origin:=932, 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)), _
TrailingMinusNumbers:=True
Cells.Select
With selection.Font
.Name = "Arial"
.Size = 8
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
With selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("C1").Select
Range(selection, selection.End(xlToRight)).Select
Range(selection, selection.End(xlDown)).Select
selection.Copy
Windows("Feuille verticale.xls").Activate
Range("A1").Select
ActiveSheet.Paste
Worksheets("Messwerte Sterilisationzyklus").Activate
Range("A1").Select

End Sub



I guess you can try to close workbook named the same as opened text file,
e.g. as below:

Workbooks(strFile).Close savechanges:=false

HTH

Mariusz C
NT_SPAM




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Closing file with Macro

Dim wks as worksheet
.....
Workbooks.OpenText Filename:=strFile _
...

'right after you open the text file:
set wks = activesheet
cells.select
...

'then when you want to close the text file.
wks.parent.close savechanges:=false




Louis wrote:

Hello

I do have a macro (see below) i'm able to open a TXT file. But how can i
close the file when the macro is over

Thanks a lot for your help

Louis

Public Sub OpenFile()
Dim strText As String
Dim strFile As String

strText = Application.InputBox("dernier 4 chiffres")

strFile = "C:\Program Files\TMI Software\ValiVacq 4.3.2\119452" & _
strText & " inst verpackt kantonsspital nidwalden app 95005v.txt"

If Dir(strFile) = "" Then Exit Sub

Workbooks.OpenText Filename:=strFile _
, Origin:=932, 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)), _
TrailingMinusNumbers:=True
Cells.Select
With selection.Font
.Name = "Arial"
.Size = 8
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
With selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("C1").Select
Range(selection, selection.End(xlToRight)).Select
Range(selection, selection.End(xlDown)).Select
selection.Copy
Windows("Feuille verticale.xls").Activate
Range("A1").Select
ActiveSheet.Paste
Worksheets("Messwerte Sterilisationzyklus").Activate
Range("A1").Select

End Sub


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Closing file with Macro

The filename in strFile in this statement:
Workbooks(strFile).Close savechanges:=false
can't include the drive and folder names--it's just the name of the file.


MC wrote:

<<Snipped

I guess you can try to close workbook named the same as opened text file,
e.g. as below:

Workbooks(strFile).Close savechanges:=false

HTH

Mariusz C
NT_SPAM


--

Dave Peterson
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
Closing file with macro dwake Excel Discussion (Misc queries) 3 December 2nd 09 05:49 PM
Macro to Save File to specific location when closing paankadu Excel Discussion (Misc queries) 3 October 26th 09 11:52 PM
How to code on Macro on saving and closing a file? Eric Excel Worksheet Functions 1 June 10th 07 01:32 PM
run macro when closing file santee Excel Programming 2 January 30th 07 03:18 PM


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

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

About Us

"It's about Microsoft Excel"