Greetings All,
I have a spreadsheet which sends account information every 30 minutes 24/7 via Outlook to company executives. My original code worked but was a little buggy sometimes and tied up my clipboard until the script was through copy/pasting. I posted in this forum and received a new code which used a different method to copy/paste the data. The only problem with the new code is that it only works if I'm logged in and my computer is unlocked. I'm pasting only a smidgen of the code below as the rest of the code which sends the email works fine. Ideally, I'd like to use the new code but needing it to work regardless of me being at my desk.
New Code
Original Code
I have a spreadsheet which sends account information every 30 minutes 24/7 via Outlook to company executives. My original code worked but was a little buggy sometimes and tied up my clipboard until the script was through copy/pasting. I posted in this forum and received a new code which used a different method to copy/paste the data. The only problem with the new code is that it only works if I'm logged in and my computer is unlocked. I'm pasting only a smidgen of the code below as the rest of the code which sends the email works fine. Ideally, I'd like to use the new code but needing it to work regardless of me being at my desk.
New Code
Code:
Public Sub ImportCMS()
Application.ScreenUpdating = False
Dim lastMod As String
Dim ws As Worksheet
Dim File1, File2 As Workbook
File1 = ActiveWorkbook.Name
Set File1 = ActiveWorkbook
Set ws = File1.Sheets("Alpha Widgets")
ws.Range("A10:R64").ClearContents
lastMod = FileDateTime("C:\Users\Desktop\ServiceLevelsSMS\IntervalScriptOutput\Alpha Widgets.txt")
ws.Range("B2") = lastMod
Set File2 = Workbooks.Open("C:\Users\Desktop\ServiceLevelsSMS\IntervalScriptOutput\Alpha Widgets.txt")
With File2.Sheets(1).Range("A1:R55")
ws.Range("A10").Resize(.Rows.Count, .Columns.Count).Value = .Value
End With
File2.Close False
Set File1 = ActiveWorkbook
Set ws = File1.Sheets("Bravo Sprockets")
ws.Range("A10:R64").ClearContents
lastMod = FileDateTime("C:\Users\Desktop\ServiceLevelsSMS\IntervalScriptOutput\Bravo Sprockets.txt")
ws.Range("B2") = lastMod
Set File2 = Workbooks.Open("C:\Users\Desktop\ServiceLevelsSMS\IntervalScriptOutput\Bravo Sprockets.txt")
With File2.Sheets(1).Range("A1:R55")
ws.Range("A10").Resize(.Rows.Count, .Columns.Count).Value = .Value
End With
File2.Close False
Original Code
Code:
Public Sub ImportCMS()
Dim File1, File2, File3, File4, File5, File6, File7 As String
File1 = ActiveWorkbook.Name
Sheets("Alpha Widgets").Select
Range("A10:R64").ClearContents
WS = ActiveSheet.Name
File2 = "C:\Users\Desktop\ServiceLevelsSMS\IntervalScriptOutput\Alpha Widgets.txt"
Workbooks.Open File2
wFile = ActiveWorkbook.Name
Range("A1:R55").Select
Selection.Copy
Windows(File1).Activate
Sheets(WS).Activate
Range("A10").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Workbooks(wFile).Close False
If ActiveSheet.Name = "Sheet1" Then
Application.GoTo Reference:="mTop"
End If
Sheets("Bravo Sprockets").Select
Range("A10:R64").ClearContents
WS = ActiveSheet.Name
File3 = "C:\Users\Desktop\ServiceLevelsSMS\IntervalScriptOutput\Bravo Sprockets.txt"
Workbooks.Open File3
wFile = ActiveWorkbook.Name
Range("A1:R55").Select
Selection.Copy
Windows(File1).Activate
Sheets(WS).Activate
Range("A10").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Workbooks(wFile).Close False
If ActiveSheet.Name = "Sheet1" Then
Application.GoTo Reference:="mTop"
End If