Solved

Error on .Range ???

Posted on 2011-09-23
6
513 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

685 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