VB如何修改excel表格的内容?
DimobjExcelAsExcel.ApplicationDimobjWorkBookAsExcel.WorkbookDimobjSheetAsExcel.Worksh...
Dim objExcel As Excel.Application
Dim objWorkBook As Excel.Workbook
Dim objSheet As Excel.Worksheet
Set objExcel = GetObject("Excel.Application")
Set objWorkBook = xlsApp.Workbooks.Open("F:\生产报表\8\" & Format(Now - 1, "yyyy.mm.dd") & "-" & Format(Now, "mm.dd") & ".xls")
objExcel.Visible = True
'设置活动工作表
Set objSheet = objExcel.Worksheets(1)
objSheet.Cells(4, 4) = "mother"
程序如上,修改无效,甚至打开文件都无效,关键是没有提示错误!! 展开
Dim objWorkBook As Excel.Workbook
Dim objSheet As Excel.Worksheet
Set objExcel = GetObject("Excel.Application")
Set objWorkBook = xlsApp.Workbooks.Open("F:\生产报表\8\" & Format(Now - 1, "yyyy.mm.dd") & "-" & Format(Now, "mm.dd") & ".xls")
objExcel.Visible = True
'设置活动工作表
Set objSheet = objExcel.Worksheets(1)
objSheet.Cells(4, 4) = "mother"
程序如上,修改无效,甚至打开文件都无效,关键是没有提示错误!! 展开
展开全部
Set xlapp = CreateObject("excel.application")
Set xlbook = xlapp.Workbooks.Open("D:\RTM Record\RTM Tester" & Date & "\Statistics\SummaryLog_RTM_without_IXX_sample.csv")
xlapp.Visible = False
Set xlSheet = xlbook.Worksheets(1)
‘中间加你想要的操作
xlbook.Close (True)
xlapp.Quit
Set xlapp = Nothing
’最后记得 要退出哦!
我想差异就在于 你的是getobject,我的是createobject,你改下试一下的吧,我一直是用这种方法!
希望对你有所帮助!
你再看下你的引用里面是否有选择下图上的选项!
更多追问追答
追问
我刚开始用的是create,后面修改为getobject,都试过了。我怀疑与打开的方式有关,是不是只读属性,workbook。open,还是不行。
追答
Private Sub Command1_Click()
Dim xlapp, xlbook, xlSheet As Variant '调用打开文件的过程。
Set xlapp = CreateObject("excel.application")
Set xlbook = xlapp.Workbooks.Open("D:\1122.xls")
xlapp.Visible = False
Set xlSheet = xlbook.Worksheets(1)
xlapp.Cells(1, 1) = "RTM_Test"
xlbook.Close (True)
xlapp.Quit
Set xlapp = Nothing
End Sub
这个代码在我电脑上试过了,你试下看看,记得在引用里面选上excel哦!
你要先在D盘下建一个“1122.xls”的excel哦
展开全部
Sub t()
Dim FilesToOpen
Application.ScreenUpdating = False
Set wb = Workbooks.Open(Filename:="F:\生产报表\8\" & Format(Now - 1, "yyyy.mm.dd") & "-" & Format(Now, "mm.dd") & ".xls")
wb.Sheets(1).Cells(4, 4) = "m"
wb.Save
wb.Close
Application.ScreenUpdating = True
End Sub
Dim FilesToOpen
Application.ScreenUpdating = False
Set wb = Workbooks.Open(Filename:="F:\生产报表\8\" & Format(Now - 1, "yyyy.mm.dd") & "-" & Format(Now, "mm.dd") & ".xls")
wb.Sheets(1).Cells(4, 4) = "m"
wb.Save
wb.Close
Application.ScreenUpdating = True
End Sub
追问
试了试可以写,想请教wb是在哪儿定义的?filestoopen是什么意思?
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询