Computing.Net > Forums > Office Software > Excel Macros

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Excel Macros

Reply to Message Icon

Name: mike engles
Date: October 23, 2005 at 14:37:48 Pacific
OS: Win XP PRO SP1
CPU/Ram: pentium2.53/1024
Comment:

Hello

I have made a macro and want it to be more general,so that I can apply it with any .log test file delivered by a audio ripping program. I want a file open at the beginning and a save as at the end.
The trouble is that the macro will only work on the original data, which is not much use.
I have been using the import data option to bring in the data which is fixed width and use it in a prepared template.

I know nothing about Visual Basic, I know that is what I need to make the macro more general.

I can post the text of the macro.
Sub format()
'
' format Macro
' Macro recorded 23/10/2005 by Engles
'

'
Range("A2").Select
With ActiveSheet.QueryTables.Add(Connection:="TEXT;O:\BBCSO\BBCSO002.log", _
Destination:=Range("A2"))
.Name = "BBCSO002"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 1, 2, 1, 9)
.TextFileFixedColumnWidths = Array(20, 15, 36, 19)
.Refresh BackgroundQuery:=False
End With
ChDir "D:\"
ActiveWorkbook.SaveAs Filename:="D:\BBCSO.xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
End Sub
Sub format()
'
' format Macro
' Macro recorded 23/10/2005 by Engles
'

'
Range("A2").Select
With ActiveSheet.QueryTables.Add(Connection:="TEXT;O:\BBCSO\BBCSO002.log", _
Destination:=Range("A2"))
.Name = "BBCSO002"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 1, 2, 1, 9)
.TextFileFixedColumnWidths = Array(20, 15, 36, 19)
.Refresh BackgroundQuery:=False
End With
ChDir "D:\"
ActiveWorkbook.SaveAs Filename:="D:\BBCSO.xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
End Sub

Thanks for your help

Mike Engles




Sponsored Link
Ads by Google

Response Number 1
Name: egkenny
Date: October 30, 2005 at 19:02:09 Pacific
Reply:

Here is a very simple example:
-------------------------

Bring up toolbox for controls
View->Toolbars->Control Toolbox

Add 2 "Command Button" controls
Add 2 "Text Box" controls

Place them something like this:

| ..A.. | ..B.. | ..C. | .D. |
-|-----|-----|-----|-----|
| ----------- ----------
1| |command| |text box|
| ----------- ----------
-|-----|-----|-----|-----|
| ----------- ----------
2| |command| |text box|
| ----------- ----------
-|-----|-----|-----|-----|

Right-click on upper "Command Button"
Select "Properties"
Change (Name) from CommandButton1 to Open_Button
Change Caption from CommandButton1 to Open

Right-click on lower "Command Button"
Select "Properties"
Change (Name) from CommandButton2 to Save_Button
Change Caption from CommandButton2 to Save

Right-click on upper "TextBox"
Select "Properties"
Change (Name) from TextBox1 to Open_Text

Right-click on lower "TextBox"
Select "Properties"
Change (Name) from TextBox2 to Save_Text

Double-click on upper "Command Button"
Double-click on lower "Command Button"
You should get these functions created:

Private Sub Open_Button_Click()
End Sub

Private Sub Save_Button_Click()
End Sub

Add your code:

Private Sub Open_Button_Click()
' other code here
ActiveSheet.QueryTables.Add(Connection:=Open_Text.Text, _
Destination:=Range("A2"))
' other code here
End Sub

Private Sub Save_Button_Click()
' other code here
ActiveWorkbook.SaveAs Filename:=Save_Text.Text, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
' other code here
End Sub


Other things you can do:
-------------------------
1. Bring up Visual Basic Editor
2. Insert "UserForm". This is a dialog box.
3. Add "Command Button" and "TextBox" controls to "UserForm".
4. With effort you can add "ComboBox" controls and use them to select drives and files from directories.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: Excel Macros

Run Excel Macro as Automated Task on Server www.computing.net/answers/office/run-excel-macro-as-automated-task-on-server/9661.html

Excel Macro read and process CSV www.computing.net/answers/office/excel-macro-read-and-process-csv/3820.html

Excel macro www.computing.net/answers/office/excel-macro/4051.html