我想使用vba在许多工作簿上执行文本到列。
我尝试了以下代码,但它只处理一个工作簿,而我希望修改所有这些代码除了" Testmac" WB。
public static List<String> getAppsFromUnknownSources(Context context)
{
List<String> apps = new ArrayList<>();
PackageManager packageManager = context.getPackageManager();
List<PackageInfo> packList = packageManager.getInstalledPackages(0);
for (int i = 0; i < packList.size(); i++)
{
PackageInfo packInfo = packList.get(i);
boolean hasEmptyInstallerPackageName = packageManager.
getInstallerPackageName(packageInfo.packageName) == null;
boolean isUserInstalledApp = (packageInfo.applicationInfo.flags &
ApplicationInfo.FLAG_SYSTEM) == 0;
if (hasEmptyInstallerPackageName && isUserInstalledApp)
{
apps.add(packInfo.packageName);
}
}
return apps;
}
答案 0 :(得分:1)
在您的代码Columns("A:A")
中隐式引用ActiveWorkbook.ActiveSheet.Columns("A:A")
,
这就是为什么它只在一张纸上工作!
以下是在所有打开的工作簿中执行此操作的代码:
请注意,我已经注释了删除列的部分(在将数据放入其中后看起来很奇怪),所以如果需要,请取消注释! ;)
Sub sdptest()
Dim w As Workbook
Dim wS As Worksheet
For Each w In Workbooks
If InStr(1, LCase(w.Name), "testmac") Then
Else
For Each wS In w.Sheets
With wS.Columns("A:A")
If Application.WorksheetFunction.CountA(.Cells) > 0 Then
.TextToColumns Destination:=Range("A1"), _
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=False, _
Semicolon:=False, _
Comma:=True, _
Space:=False, _
Other:=False, _
FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), TrailingMinusNumbers:=True
'.Delete Shift:=xlToLeft
Else
End If
End With 'wS.Columns("A:A")
Next wS
End If
Next w
End Sub