I am posting all of my code here. You can see I am trying to set three
different workbooks within this macro. And count the rows for two the other
workbooks. I am a little over half way finished with this macro, so be
patient with the code.
Further, there is another error that someone might help me with. I can't
figure out how to set the password to refresh the data. This macro will be
running at 3am so, no, I won't be here to input the password.
Option Explicit
Private Sub Workbook_Open()
'Upon open this should refresh data
Dim i As Integer, t As Integer
Dim wbname As Variant
Dim wb As Workbook, data As Workbook
Dim qrow As Integer
Set data = Workbooks("TER Master Data Extraction")
'Refresh Data
'Sheets("Source Data").Select
'Cells.Select
'Selection.QueryTable.Refresh BackgroundQuery:=True
Range("A1").Select
Application.CutCopyMode = False
ActiveSheet.UsedRange.Select
Selection.Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
wbname = "TERData " & Format(Date, "mm-dd-yyyy") & " " & Format(Time,
"h.mm.AM/PM")
ChDir "D:\documents and settings\nseib\Desktop\Time Exception Reports"
Workbooks.Open Filename:= _
"D:\documents and settings\nseib\Desktop\Time Exception Reports\Log
TER Data Extraction.xls"
Range("O1").Select
ActiveCell.Value = wbname
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.CutCopyMode = False
ActiveWorkbook.SaveAs Filename:= _
"D:\TERData\" & wbname & ".xls", FileFormat:=xlNormal, Password:="", _
WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
Set wb = Workbooks(wbname)
Call LogDataExtraction
wb.Activate
Range("A1").Select
qrow = wb.UsedRange.Rows.Count
MsgBox qrow
Rows("1:1").RowHeight = 24.75
Rows("1:1").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("A2").Select
Columns("A:A").ColumnWidth = 19.29
Columns("B:B").ColumnWidth = 17.71
Columns("C:C").ColumnWidth = 15.71
Columns("D
").ColumnWidth = 23.43
Columns("E:E").ColumnWidth = 21
Columns("F:F").ColumnWidth = 19.57
Columns("G:G").ColumnWidth = 25.86
Columns("H:H").ColumnWidth = 25.86
Columns("I:I").ColumnWidth = 23.43
Columns("J:J").ColumnWidth = 56.14
Columns("K:K").ColumnWidth = 46
Columns("L:L").ColumnWidth = 22.71
Range("J1").Select
Selection.AutoFilter
Range("A1
1209").Sort Key1:=Range("J1"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
'ActiveWorkbook.Save
'ActiveWorkbook.SendMail Array("(e-mail address removed)", "
(e-mail address removed)"), _
"Time Exception Data"
'ActiveWorkbook.Close
End Sub
Private Sub LogDataExtraction()
'Updates Refresh Log
'Time and Date stamp will come from this page
Dim log As Workbook
Dim qrow As Integer
Dim wbname As String
ChDir "D:\documents and settings\nseib\Desktop\Time Exception Reports"
Workbooks.Open Filename:= _
"D:\documents and settings\nseib\Desktop\Time Exception Reports\Log
TER Data Extraction.xls"
Set log = Workbooks("Log TER Data Extraction")
log.Activate
Range("A1").Select
qrow = Workbooks("Log TER Data Extraction").Sheets("Refresh
Log").Cells(Rows.Count, 1).End(xlUp).Row
MsgBox qrow
wbname = Range("O1").Value
REPEAT:
Range("B" & qrow).Select
If IsEmpty(ActiveCell) Then
ActiveCell.Offset(0, -1) = (ActiveCell.Offset(-1, -1).Value + 1)
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
wbname & ".xls", TextToDisplay:="TERData" & ActiveCell.Offset(0,
-1).Value
ActiveCell.Offset(0, 1) = Format(Date, "m-dd-yyyy")
ActiveCell.Offset(0, 2) = Format(Time, "h:mm:ss AM/PM")
Range("A" & (qrow + 1)).Select
ActiveWorkbook.Save
' ActiveWorkbook.Close
Else
qrow = qrow + 1
GoTo REPEAT
End If
End Sub