vba - 如何将变量分配给具有部分已知名称的 Excel 工作表
问题描述
有人可以帮我解决以下问题:
我对“ Set ch1 =
”有疑问
文件名(或者更确切地说,文件名的最后几个字符每天都会略有变化),因此我需要添加通配符 (*) 或类似的东西。
如何使用名称更改的文件“设置 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
推荐阅读
- npm - 如何使用全局 scss 变量覆盖我的节点模块
- python - Python:加载包含数组的文本文件
- sql - 在 SQL(Oracle) 时间查询中,我得到月份而不是分钟
- java - UnreachableBrowserException: 无法启动新会话 可能的原因是远程服务器地址无效或浏览器启动失败
- java - 重复的音频剪辑不播放 - Java
- nginx - 带有 SSL 的 ActionCable 在生产环境中不起作用
- python - 如何在Opencv中获取校准函数的参数
- node.js - NodeJS使用crypo计算MD5哈希的不同结果
- javascript - vue js中通过父组件上的方法动态绑定一个类
- android - kotlin - 从可绘制文件夹中的图像数组中获取图像