gpt4 book ai didi

vb.net - 打开Excel文件并检查它是否是只读的

转载 作者:行者123 更新时间:2023-12-04 20:17:49 26 4
gpt4 key购买 nike

在尝试写入之前,我需要检查 Excel 文件是否为只读。这是我的代码:

  Private Sub ButtonTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonTest.Click
Dim UnapprovedAcctFile As String = "W:\TOM\ERIC\Award_Letters\Accounting Files\Unapproved\" & StatVar.xlApp.Sheets("New Calculator Input").Range("D30").Value & ".xlsx"
Dim UnapprovedFileName = StatVar.xlApp.Sheets("New Calculator Input").Range("D30").Value & ".xlsx"
If Not IO.File.Exists(UnapprovedAcctFile) Then
MessageBox.Show("Could not locate the accounting file for this school. Please contact an administrator for assistance.")
Exit Sub
Else
StatVar.xlWBUnapprovedAcctFile = StatVar.xlApp.Workbooks.Open(UnapprovedAcctFile)
If GetAttr(UnapprovedFileName) And vbReadOnly Then
MessageBox.Show("File is read only.")
End If
End If
End Sub

它在这里抛出异常:
If GetAttr(UnapprovedFileName) And vbReadOnly Then   

异常(exception)是“找不到文件“East.xlsx”。但是,该文件打开,因此它确实存在。我以为我需要在没有路径的情况下引用文件,但显然我在这里有点偏离。有什么建议吗?

最佳答案

解决方案:

If StatVar.xlApp.ActiveWorkbook.ReadOnly = True Then

关于vb.net - 打开Excel文件并检查它是否是只读的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17791736/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com