Solved

Error on .Range ???

Posted on 2011-09-23
6
509 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now