I want to put the value 6 in cell A1 on sheet1 of a file named book1.xlsm on my desktop. Can I do this without actually opening the file?
I want to put the value 6 in cell A1 on sheet1 of a file named book1.xlsm on my desktop. Can I do this without actually opening the file?
I could be wrong, but I don't think so. However, using VBA, you can open the book, insert it, then close it, without seeing it open and close.
Ok cool. I'm looking into how to do this, but any help would be appreciated. Thanks.
Something like this would work:
HTH![]()
Sub OpenFile() Dim strFile As String Dim Wkb As Workbook strFile = "C:\Temp\book1.xlsm" Application.ScreenUpdating = False 'used so you don't see the file opening Set Wkb = Workbooks.Open(strFile) Wkb.Worksheets(1).Range("A1") = 6 Wkb.Close SaveChanges:=True Application.ScreenUpdating = True End Sub
Jason
Thanks. I tried it on my own, and then I tried your way, and both times I get the same error.:
Run time error '1004'
Application-defined or object-defined error.
Any thoughts?
Ok, somehow I got that one to work, but you can still see the file open for a second and then close. Is there any way to have this all happen behind the scenes?
Hi
try the following codes. replace the filepath (G:\macro\) with yours.
Ravi![]()
Application.DisplayAlerts = False Workbooks.Open Filename:="G:\macro\book1.xlsm" Sheets("Sheet1").Cells(1, 1) = 6 ActiveWorkbook.Save ActiveWorkbook.Close Application.DisplayAlerts = True MsgBox "Data entered in cell A1"
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks