标题: 由于每次原始数据的名称都不一样,如何每次自动获取名称? [打印本页] 作者: 棋行天下黄 时间: 2009-6-9 23:25 标题: 由于每次原始数据的名称都不一样,如何每次自动获取名称? 由于每次原始数据的名称都不一样,如何每次自动获取名称?Sub Macro1()
'
' Macro1 Macro
' 宏由 黄勇 录制,时间: 2009-6-9
'
' 快捷键: Ctrl+k
'
ChDir "C:\Documents and Settings\Administrator\My Documents\宏标卡"
Workbooks.Open Filename:= _
"C:\Documents and Settings\Administrator\My Documents\宏标卡\门店标卡(武汉).xls"
ActiveWindow.SmallScroll Down:=-48
Range("A1:C42").Select
Range("A40").Activate
Selection.Copy
Windows("原始数据.xls").Activate
Sheets.Add
ActiveSheet.Paste
Windows("门店标卡(武汉).xls").Activate
Sheets("品类对应部门").Select
ActiveWindow.SmallScroll Down:=-21
Range("A1:C43").Select
Range("C15").Activate
Application.CutCopyMode = False
Selection.Copy
Windows("原始数据.xls").Activate
Sheets.Add
ActiveSheet.Paste
Sheets("原始数据").Select
Windows("门店标卡(武汉).xls").Activate
ActiveWindow.Close
End Sub
需要完整代码代替上面原始数据的名字,即任意文件名按ctrl+k即可,谢谢作者: 方漠 时间: 2009-6-9 23:44
Here is a sample for you, try to get the variant with Activesheet.name/activeworkbook.name/activewindow.name.
Sub FormatBalance()
Dim Str As String
Dim ab As Variant
Dim Lrow As Long, I As Long, T As Long
Dim Fcl As Range
Str = Workbooks.Application.GetOpenFilename
ab = Str
If ab = False Then
MsgBox "You didn't select the TXT file. Cancelling...", vbExclamation, "Your Company Name"
Else
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Lrow = Range("A65536").End(xlUp).Row
T = 8
For I = 8 To Lrow 'Remove the Redundant Line
If Left(Range("A" & I), 9) = "---------" Then
Rows(I & ":" & I).Delete
I = I - 1
End If
If I > 25 And Left(Range("A" & I), 3) <> "832" Then
Rows(I & ":" & I).Delete
I = I - 1
End If
T = T + 1
If T > Lrow Then Exit For
Next I
For Each Fcl In ActiveSheet.UsedRange 'Remove the Redundant Blank
Fcl = Trim(Fcl.Value)
Next
With Selection.Interior
.ColorIndex = 12
.Pattern = xlSolid
End With
With Selection.Font
.Name = "Arial"
.Size = 10
.ColorIndex = 2
.Bold = True
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
Columns("A:A").ColumnWidth = 9.5
Columns("B").EntireColumn.AutoFit
I = Range("C65536").End(xlUp).Row
Columns("H:H").Select
Selection.Insert Shift:=xlToRight
Range("H9:H10").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
Selection.Merge
ActiveCell.FormulaR1C1 = "Diff +/-"
Range("H11:H" & I).Select
ActiveCell.FormulaR1C1 = "=RC[-1]-RC[-2]"
Selection.FillDown