【发布时间】:2023-01-01 12:49:58
【问题描述】:
我在 vb.net 中有以下代码,它打开 Excel 文件,然后要求用户选择范围,所选范围有“=”,如果我手动删除它代码将继续,如果我没有我得到错误
请注意,我使用的是 visual studio 2022 和 excel 365
`
Private Sub OpenExcelFile()
' Open the Excel file
xlWorkbook = xlApp.Workbooks.Open(selectedFile)
xlWorksheet = xlWorkbook.Worksheets(1)
' Make the Excel application visible
xlApp.Visible = True
' Prompt the user to enter the range they want to select
Dim rangeInput As String = xlApp.InputBox("Enter the range you want to select (e.g. A1:B2):", "Select Range")
' Remove the "=" character from the beginning of the range input, if present
rangeInput = rangeInput.Replace("=", "")
' Select the range
' Display the selected range in a label
MsgBox("You have selected the range: " & rangeInput)
' Display the selected range in TextBox2
TextBox2.Text = rangeInput
End Sub
`
我试过修剪、更换,但没有任何效果:(
【问题讨论】: