Nachtschade
New Member
- Joined
- Dec 6, 2013
- Messages
- 30
I have this macro:
I found this and modified it to my use when I was googling for a way to have Excel import the contents of a .txt file.
This macro is working fine when I execute it from Excel.
However I am trying to execute it using a vbscript:
The script does what it should do. It runs the macro, but the macro doesn't copy the content of the txt file into Excel the way it does when I run from Excel itself.
Does anyone what the problem is here?
Is it some kind of focus thing? Or maybe something with admin rights?
VBA Code:
Sub getpathnp()
Application.ScreenUpdating = False
Dim wbExcel As Workbook, wbText As Workbook
Dim wsExcel As Worksheet
Set wbExcel = ThisWorkbook 'specify here which Excel file the text file’s content is to be pasted into
Set wsExcel = wbExcel.Sheets("Timeplay") 'specify here which worksheet to use
Set wbText = Workbooks.Open("A:\nppath.txt") 'add here the path of your text file
wbText.Sheets(1).Cells.Copy wsExcel.Cells
On Error Resume Next
wbText.Close SaveChanges:=False
If Sheets("Timeplay").Range("A1") = Sheets("Invoer TP").Range("A1") Then
Call TimePlay
Else
I found this and modified it to my use when I was googling for a way to have Excel import the contents of a .txt file.
This macro is working fine when I execute it from Excel.
However I am trying to execute it using a vbscript:
Code:
Option Explicit
Dim xlApp, xlBook
Set xlBook = GetObject("A:\test.xlsm")
Set xlApp = xlBook.Application
xlApp.Run "getpathnp"
Set xlBook = Nothing
Set xlApp = Nothing
WScript.Quit
The script does what it should do. It runs the macro, but the macro doesn't copy the content of the txt file into Excel the way it does when I run from Excel itself.
Does anyone what the problem is here?
Is it some kind of focus thing? Or maybe something with admin rights?