-1

I created Excel macro, in which I'm searching current date in other, closed workbook and getting the number of the row where this date is. Everything works perfectly, but only if I'm opening this other workbook.

Is there a possibility to make the code works without opening this workbook? Or maybe it's possible to make this workbook not to appear, because I don't want it to appear on the screen?

I've tried many methods, e.g. Application.ScreenUpdating = false or ActiveWorkbook.Windows(1).Visible = False but it doesn't work the way I want it.

lokusking
  • 7,396
  • 13
  • 38
  • 57
  • 1
    mate, there are tons of this very same subject questions and answers spread over this site. just search for them and struggle with the solution to the issue most similar to yours – user3598756 Sep 14 '16 at 05:53
  • Possible duplicate of [Open Excel file for reading with VBA without display](http://stackoverflow.com/questions/579797/open-excel-file-for-reading-with-vba-without-display) – niton Mar 24 '17 at 00:28

1 Answers1

0

You need to create a new Excel Application to be able to hide the Window:

Dim xlApp As New Excel.Application 'New Excel Application
Dim xlWB As Excel.Workbook 'Workbook Object

xlApp.Visible = False 'Hide Application

Set xlWB = xlApp.Workbooks.Open("PATH TO FILE") 'Open File in new App

'do something here
xlWB.Sheets(1).Cells(1, 1).Value = "Hello, this is a Test"

xlWB.Close 'Close Workbook (Use SaveChanges:=True to save changes)
Set xlWB = Nothing 'Clear Object
xlApp.Quit 'Quit Excel App
Set xlApp = Nothing 'Clear Object
gizlmo
  • 1,882
  • 1
  • 14
  • 14