新窗口未与 VBScript 聚焦 [英] New window not in focus with VBScript

查看:26
本文介绍了新窗口未与 VBScript 聚焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段简单的代码,它要求用户导航到一个 .csv 文件,它会计算列数(一个更大项目的一部分),虽然它运行良好,但我真的有烦人的问题...当窗口打开提示用户导航到文件时,它没有处于焦点状态,而是位于先前处于焦点状态的窗口后面.谁能指出哪里出了问题?

I've a simple piece of code which asks a user to navigate to a .csv file and it will count the number of columns (part of a much bigger project) and while it works perfectly, I'm having a really annoying issue... When the window opens prompting the user to navigate to the file, it isn't in focus and sits behind the window previously in focus. Can anyone point out whats gone wrong?

我使用的是 64 位 Windows 7 和 IE 9 版本 9.0.8112.16421

I'm using Windows 7 64-bit running with IE 9 Version 9.0.8112.16421

'Get location of .csv file

'set the type of dialog box you want to use: 1 = Open 2 = SaveAs 3 = File Picker 4 = Folder Picker
Const msoFileDialogOpen = 1

Set fso = CreateObject("Scripting.FileSystemObject")
Set objWord = CreateObject("Word.Application")
Set WshShell = CreateObject("WScript.Shell")
'Launch at default path
strInitialPath = WshShell.ExpandEnvironmentStrings("C:\")
objWord.ChangeFileOpenDirectory(strInitialPath)

With objWord.FileDialog(msoFileDialogOpen)
   .Title = "Select the file to process"
   .AllowMultiSelect = False
   .Filters.Clear
    .Filters.Add "CSVFiles", "*.csv"
   .Filters.Add "All Files", "*.*"               
   If .Show = -1 Then 
      For Each File in .SelectedItems 
        Set objFile = fso.GetFile(File) 
      Next 
   End If
End With
'Close Word
objWord.Quit

'Counts columns in csv file if delimiter is comma

Dim oFso, oReg, sData, lCount
Const ForReading = 1
Set oReg = New RegExp
Set oFso = CreateObject("Scripting.FileSystemObject")
sData = oFso.OpenTextFile(objFile.Path, ForReading).ReadLine
With oReg
.Global = True
'Check Pattern (delimiter, has qualifier?)
'.Pattern = ","
'.Pattern = "|"
'.Pattern = "^"
.Pattern = ""","""
'.Pattern = """|"""
'.Pattern = """^"""
lCount = .Execute(sData).Count + 1
End With
WScript.Echo lCount
Set oFso = Nothing
Set oReg = Nothing

谢谢各位!

推荐答案

您是否尝试过 AppActivate?

CreateObject("WScript.Shell").AppActivate "Your window title here..."

这篇关于新窗口未与 VBScript 聚焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆