ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro opening a file (https://www.excelbanter.com/excel-programming/396447-macro-opening-file.html)

Leon

macro opening a file
 
Hello, I want a macro to pause to select manually a file, and then format it.
I have attached macro, how to modify it?
' Controller_Openen_decimale_punt Macro
' Macro recorded 7/4/2007 by CROMMENTUIJN Leon
'

'
ChDir "C:"
Workbooks.OpenText Filename:="C:\Emerson\log.htm", Origin:=437, StartRow _
:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(8,
1), Array( _
14, 1), Array(15, 1)), TrailingMinusNumbers:=True
Columns("C:C").Select
Selection.Delete Shift:=xlToLeft
Columns("A:C").Select
Range("C1").Activate
Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets("log").Range("A1:C192"),
PlotBy:= _
xlColumns
ActiveChart.Location Whe=xlLocationAsNewSheet
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Temperatuurverloop"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "[C]"
.Axes(xlValue, xlPrimary).HasTitle = False
End With
End Sub


joel

macro opening a file
 
Use GetOpenFileName Method

Sub test1()

fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")

If fileToOpen < False Then
Workbooks.OpenText Filename:=fileToOpen, _
Origin:=437, _
StartRow:=1, _
DataType:=xlFixedWidth, _
FieldInfo:= _
Array(Array(0, 1), Array(8, 1), Array(14, 1), Array(15, 1)), _
TrailingMinusNumbers:=True

Columns("C:C").Select
Selection.Delete Shift:=xlToLeft
Columns("A:C").Select
Range("C1").Activate
Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData _
Source:=Sheets("log").Range("A1:C192"), _
PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsNewSheet

With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Temperatuurverloop"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "[C]"
.Axes(xlValue, xlPrimary).HasTitle = False
End With
End If

End Sub


"Leon" wrote:

Hello, I want a macro to pause to select manually a file, and then format it.
I have attached macro, how to modify it?
' Controller_Openen_decimale_punt Macro
' Macro recorded 7/4/2007 by CROMMENTUIJN Leon
'

'
ChDir "C:"
Workbooks.OpenText Filename:="C:\Emerson\log.htm", Origin:=437, StartRow _
:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(8,
1), Array( _
14, 1), Array(15, 1)), TrailingMinusNumbers:=True
Columns("C:C").Select
Selection.Delete Shift:=xlToLeft
Columns("A:C").Select
Range("C1").Activate
Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets("log").Range("A1:C192"),
PlotBy:= _
xlColumns
ActiveChart.Location Whe=xlLocationAsNewSheet
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Temperatuurverloop"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "[C]"
.Axes(xlValue, xlPrimary).HasTitle = False
End With
End Sub



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com