Solved

Error on .Range ???

Posted on 2011-09-23
6
512 Views
Last Modified: 2012-05-12
I'm getting an "unknown runtime error" on line 22 below.  Can someone help me out?
 
' Open the TOAD Excel Spreadsheet
Dim strPsoftExtract
strPsoftExtract = "Y:\HT_BI_HEE_EXTRACT_V2.xls"
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(strPsoftExtract)
Dim frmla
Dim i 
Dim rg 
objExcel.ScreenUpdating = False

'Insert column headers in col Z
objExcel.Cells(1, 25).Value = "ORG UNIT1 NAME"

With objExcel.ActiveSheet
	Set rg = .Range("Y2") 
	Set rg = .Range(rg, .Cells(.Rows.Count, rg.Column).End(-4162)) 'xLUp = -4162

'This inserts the VLOOKUP formula into cell Z2, AA2.
	For i = 1 To 2
    	frmla = "=VLOOKUP($Y2,'J:\[ManagerLevels.xls]sheet1!$A$2:$D$16," & (2 * i) & ",FALSE)"
    	.Range("Z2").Offset(0, i - 1).Formula = frmla
	Next
End With

'This copies the formula all the way down columns Z and AA.
'and then replaces the formula result with the value only (like doing Paste Special --> Values)
With rg.Offset(0, 25).Resize(, 2)
    .FillDown
    .Formula = .Value
End With

objExcel.ScreenUpdating = True

' Retrieve the separate Date components. 
Dim TodayYYYY, TodayMM, TodayDD
TodayYYYY = Year(Date) 
TodayMM   = Month(Date) 
TodayDD   = Day(Date) 

' Save the sheet - appending TodaysDate to the end of the file-name.
objWorkbook.SaveAs "Y:\HT_BI_HEE_EXTRACT_V2_" & TodayYYYY & "-" & TodayMM & "-" & TodayDD & ".xls"

' Delete the original Psoft Extract
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile strPsoftExtract, True

' Close Excel with the Quit method on the Application object.
objWorkbook.Application.Quit

' Release the object variable.
Set objExcel = Nothing

Open in new window

0
Comment
Question by:OGSan
  • 4
  • 2
6 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 36590342
Are you absolutely certain that on Drive J there is a file with that name?

Are you absolutely certain that, if that file exists, it has a worksheet named sheet1?

Is that file password protected?

If J is a mapped network drive, is it possible that the account running the VBScript does not have the same drive mapping for J?  (Have you tried using a UNC path instead?)
0
 
LVL 1

Author Comment

by:OGSan
ID: 36590605
Hmm, I assumed that line 14 ("With objExcel.ActiveSheet") was referring to the file defined on line 3 ("strPsoftExtract = "Y:\HT_BI_HEE_EXTRACT_V2.xls")...?
I took your suggestion and changed the mapped drive references into UNC path names.
I still get an error on the same line - but it says, "invalid flags."  ???
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 36590766
What does line 14 have to do with anything?  You asked about the error on Line 22.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:OGSan
ID: 36590911
Line 14 is where the With loop begins that the .Range instruction refers to on Line 22...doesn't it?  Am I way off track?  Let me know because I certainly don't.  Thanks!
0
 
LVL 1

Accepted Solution

by:
OGSan earned 0 total points
ID: 36602598
Found it - Line 20 had a missing single quote, needed following the sheet1 reference.
0
 
LVL 1

Author Closing Comment

by:OGSan
ID: 36895911
Found bad reference
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question