gpt4 book ai didi

vba - 如何将变量分配给名称部分已知的 Excel 工作表

转载 作者:行者123 更新时间:2023-12-02 08:36:52 24 4
gpt4 key购买 nike

有人可以帮我解决以下问题吗:

我对“Set ch1 =”有疑问

文件名(或者更确切地说,其名称的最后几个字符每天都会略有变化),因此我需要添加通配符(*)或类似的内容。

如何使用名称更改的文件“Set ch1 =”?

这是我开发的部分代码。

Option Explicit
Sub Open_Latest_Cheque()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Call Open_Latest_File

Dim ch1 As Workbook, AC As Workbook, temp As Workbook
Dim ch1ws As Worksheet, ACws As Worksheet
Dim ACwsLR As Long, tempName As String

**Set ch1 = Workbooks("Sum100123.csv")**
Set ch1ws = ch1.Sheets(1)
Set AC = Workbooks("Mon.xlsm")
Set ACws = AC.Sheets("Data")

Dim MyPath As String, MyFile As String, LatestFile As String
Dim LatestDate As Date, LMD As Date.............

谢谢

最佳答案

试试这个:

Sub test_partial_name()

Dim pt_nm As Workbook

For Each pt_nm In Application.Workbooks
If (pt_nm.Name) Like "Sum1#123.csv" Then
Exit For
End If

Next pt_nm
If Not pt_nm Is Nothing Then
pt_nm.Activate
Else
MsgBox "The file has not opened!"
End If

With Sheets(1)

Cells(1, 1).Value = "its working? Yes"

End With

关于vba - 如何将变量分配给名称部分已知的 Excel 工作表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52701477/

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