【问题标题】:checking if the file name is equals to other files cell value检查文件名是否等于其他文件单元格值
【发布时间】:2020-07-02 22:40:32
【问题描述】:

我有一个包含变量名称的主 Excel 文件。 我的 vba 代码可以让我从 masterFile 打开另一个 Excel 文件。从此代码

With Application.FileDialog(msoFileDialogFilePicker)
    .InitialView = msoFileDialogViewDetails
    .Title = "Bitte die neue Exceldatei(*.xls) für die Verknüpfungsaktualisierung auswählen"
    .ButtonName = "Auswählen"
    .InitialFileName = Worksheets("Vorgaben").Range("C8").Value & "*.xlsm"
    .AllowMultiSelect = False

    If .Show = 0 Then Exit Sub

    sPfad = VBA.CurDir
    vDatei = .SelectedItems(1)
    sExcelFile = Mid(vDatei, Len(sPfad) + 2)
End With

NeuerLink = vDatei
Workbooks.Open Filename:=NeuerLink

osman = Right(NeuerLink, Len(NeuerLink) - InStrRev(NeuerLink, "\"))

我的问题是,当我打开这个新文件时,单元格 F6 中的值应该等于我的变量名称主文件的值。 如果这是真的,我想继续我的代码,当单元格 F6 有不同的值时,我想有一条错误消息,它是“错误”。

我该怎么做?

【问题讨论】:

  • 什么是变量名主文件?
  • 我可以用不同的名称保存它,在我的程序中,变量称为 anan 并且 anan 包含一些用户输入,这已经可以正常工作了。我只需要检查这个变量 anan sth like if anan= Worksheets.Range or shr like that I can't figure out

标签: excel vba macos


【解决方案1】:

这是一个您可以在代码中使用的 If 语句示例:

Sub IfExample()

    ' Here is where your existing code can go.

    If Cells(6, 6).Value <> anan Then
        MsgBox ("Error")
        GoTo ExitHere
    End If

    ' Here is where you can put the code that you want to continue to.


ExitHere:

End Sub

【讨论】:

  • 那么I6的值是多少?
  • 我不知道 I6 中有什么。 if 语句基于您的问题描述中的这句话:“当我打开这个新文件时,单元格 F6 中的值应该等于我的变量名称主文件的值”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-10-30
  • 1970-01-01
  • 2016-09-30
  • 2017-07-09
  • 1970-01-01
  • 2021-02-10
  • 1970-01-01
相关资源
最近更新 更多