Share via

VBA Application.OnTime

Anonymous
2013-05-09T14:31:28+00:00

Hello,

I have two different macros that I need to run simultaneously. One is updating a data set, the other updates an .htm page. I'm guessing I need to combine the code into a single macro as both macros using copy and paste functions.

The code for the two macros is below. I have tried various combinations of inserting the code from the second set of code into the first and am getting error messages...somethings conflicting. Any help? And or alternate solutions?

Sub AddToPriceHistory()

Application.ScreenUpdating = False

dtime = Now + TimeValue("00:00:01")
Application.OnTime dtime, "AddToPriceHistory"
Range("A4:bk4").Select
Selection.Copy
Range("A9").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

.htm macro:

Sub AddToPriceHistory()

Application.ScreenUpdating = False

dtime = Now + TimeValue("00:00:01")
Application.OnTime dtime, "AddToPriceHistory"
Calculate
With ActiveWorkbook.PublishObjects.Add(xlSourceRange, _
"C:\Users\Michael\Documents\Htm Test.htm", "Sheet1", "$E$4:$J$4", xlHtmlStatic _
, "Book1_19935", "")
.Publish (True)
.AutoRepublish = False
End With
End Sub

Thanks in Advance.

MCH

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. HansV 462.6K Reputation points
    2013-05-09T15:13:49+00:00

    Running a procedure to create a file every second is not a good idea - if the file is not ready yet you'd get conflicts. Try this:

    Sub AddToPriceHistory()

        Application.ScreenUpdating = False

        dtime = Now + TimeValue("00:01:00")

        Application.OnTime dtime, "AddToPriceHistory"

        Range("A4:BK4").Copy

        Range("A9").PasteSpecial Paste:=xlPasteValues

        Range("A9").PasteSpecial Paste:=xlPasteFormats

        Application.CutCopyMode = False

        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

        Calculate

        With ActiveWorkbook.PublishObjects.Add(xlSourceRange, _

                "C:\Users\Michael\Documents\Htm Test.htm", "Sheet1", _

                "$E$4:$J$4", xlHtmlStatic, "Book1_19935", "")

            .Publish True

            .AutoRepublish = False

        End With

        Application.ScreenUpdating = True

     End Sub

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2013-05-09T15:05:25+00:00

    I think I got it working.

    Was this answer helpful?

    0 comments No comments