如何激活具有部分名称的工作簿?

时间:2018-12-20 02:46:12

标签: excel vba

我正在尝试激活具有部分名称的工作簿。

工作簿始终称为“ Task_State_(Pivot)_xxxxxx”,x是随机数字,这些数字是要更改的数字。

我的代码:

Sub changingWorkbooks()

Dim wb As Workbook
Dim excelfile As String

'deletes the table (have to eventually put that at the beginning of my macro)
Windows("macro").Activate
Sheets(1).Select
Rows("3:3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp

For Each wb In Application.Workbooks
    If Left(wb.Name, 10) = "Task_State" Then
        excelfile = wb.Name 
    End If
Next wb

'going from horasphere data status+date, making it readable by
' converting it with the comma and pasting it into your masterfile table.
'have to find a way to have the macro find the file without a name
' as the name will always change.
Workbooks(excelfile).Activate
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
    Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
    :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
    Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1 _
    ), Array(14, 1), Array(15, 1), Array(16, 1)), TrailingMinusNumbers:=True
'this top part is to make the data readable by going into Data - Text to columns - etc

我遇到运行时错误:输入不匹配

我的错误发生在这里:Workbooks(excelfile).Activate

0 个答案:

没有答案