检查文件名是否等于其他文件单元格值

时间:2016-03-01 14:34:56

标签: excel vba excel-vba excel-vba-mac

我有一个主Excel文件,它有一个变量Name。 我的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, "\"))

我的问题是,当我打开这个新文件时,Cell F6中的值应该等于我的变量Name masterfile的值。 如果这是真的我想继续我的代码,当Cell F6有不同的值时,我想有一个错误消息,即sais"错误"。

我该怎么做?

1 个答案:

答案 0 :(得分:0)

以下是可以与代码一起使用的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