PC Review


Reply
Thread Tools Rate Thread

Closing file with Macro

 
 
=?Utf-8?B?TG91aXM=?=
Guest
Posts: n/a
 
      9th Nov 2007
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

 
Reply With Quote
 
 
 
 
MC
Guest
Posts: n/a
 
      9th Nov 2007

"Louis" <(E-Mail Removed)> wrote in message
news:B274DBDE-B85D-4F23-8FD4-(E-Mail Removed)...
> 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
(E-Mail Removed)NT_SPAM




 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      9th Nov 2007
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
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      9th Nov 2007
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
> (E-Mail Removed)NT_SPAM


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing file with macro dwake Microsoft Excel Misc 3 2nd Dec 2009 05:49 PM
Run macro after closing a table or file.... Walt Microsoft Access Queries 5 21st Oct 2009 10:03 PM
How to code on Macro on saving and closing a file? =?Utf-8?B?RXJpYw==?= Microsoft Excel Worksheet Functions 1 10th Jun 2007 01:32 PM
run macro when closing file =?Utf-8?B?c2FudGVl?= Microsoft Excel Programming 2 30th Jan 2007 03:18 PM
Personal Macro File Closing Error Sue Kelley Microsoft Excel Misc 1 19th Feb 2004 03:18 PM


Features
 

Advertising
 

Newsgroups
 


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