Silently Run Macro in Background

Sargad_Strut

New Member
Joined
Mar 28, 2014
Messages
39
Hi guys,

So this is what I'm trying to do. I've created a workbook that pulls data from an Access query, updates the data from an external source, and then creates a text file (with some dalay for the data to update) that will be imported and rewrite current values in the Access database.
In an ideal world I would like this to run say every five minutes, without noticing. I have tested to run the Workbook via the Scheduler, bud I'd like to make it smoother than that.

Is there any way I could run this without noticing? Any kind of input, even if it extends beyond VBA coding would be very much appreciated!


Private Sub Auto_Open()
Application.OnTime Now + TimeValue("00:00:05"), "GenerateTextfile"
End Sub


Sub GenerateTextfile()


Dim FilePath As String
Dim CellData As String
Dim LastCol As Integer
Dim LastRow As Integer


LastCol = 3
LastRow = Blad2.Range("F2").Value

Blad2.Range("A2").Activate

CellData = ""

FilePath = Application.DefaultFilePath & "\MyFile.txt"

Open FilePath For Output As #2

For i = 1 To LastRow
For j = 1 To LastCol
If j = LastCol Then
CellData = CellData + Trim(ActiveCell(i, j).Value)
Else
CellData = CellData + Trim(ActiveCell(i, j).Value) + vbTab
End If
Next j
Write #2, CellData
CellData = ""
Next i

Close #2

End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

dispelthemyth

Well-known Member
Joined
Mar 16, 2006
Messages
654
Try using the below at the start of your macro then change the false to true and put that at the end

Rich (BB code):
Application.ScreenUpdating = False

Do you get any warning messages, or just see what the macro is doing?

if you do see prompts and wish to ignore, you can use

Rich (BB code):
Application.DisplayAlerts = False
Again put at the beginning with False and True at the end</pre>
 
Last edited:

Sargad_Strut

New Member
Joined
Mar 28, 2014
Messages
39
Thank you for replying dispelthemyth!

Ok, so I tried your suggestion but it didn't really change anything as far as I noticed.
I've also added this at the end:

ThisWorkbook.Saved = TrueApplication.Quit
Application.ActiveWindow.Close SaveChanges:=True
ActiveWorkbook.Close SaveChanges:=True

So at the moment the workbook opens, updates the values, saves the text file, and closes. Everything working just fine.
But I'd simply like to make it run invisibly. (Probably violating the whole thing since the macro within Excel can't really run without opening up the application)

Any thoughts?
Thanks again
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,193
Messages
5,768,772
Members
425,492
Latest member
blueexcel123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top