Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile Error

Status
Not open for further replies.

LGMan

MIS
Aug 27, 2003
233
GB
Hi, until recently my piece of code worked, ran once each week, but now no longer works due to a compile error. I'm using Excel 2010 and had a load of updates recently.
routine falls over at the fname variable. (shown in red)
Cell K1 holds the date and has 'dd-mmm' custom format so appears as '30-Oct'
Code:
Dim Fname As String
    Dim Ans As Integer
    Dim Title As String
    Dim Config1 As Integer
    Dim Config2 As Integer
    Dim thisWb As Workbook
    Set thisWb = ActiveWorkbook
    Fname = Sheets("Master").Range("k1").Text
    Config1 = vbYesNo + vbDefaultButton2 + vbQuestion
    Config2 = vbOKOnly + vbInformation
 
    Title = "Weekly Process"
 
    Ans = MsgBox("Have you copied over the latest data?", Config1, Title)
    Select Case Ans
 
    Case vbYes
 
        Columns("A:N").Copy
        Workbooks.Add
    ActiveWorkbook.SaveAs Filename:=thisWb.Path & "\Weekly data week ending " & Fname
    ActiveWindow.DisplayGridlines = False
 
 
    Windows("Data Master for Week Ending files.xlsm").Activate
        Columns("A:N").Select
        Selection.Copy
        Windows("Weekly data week ending " & [COLOR=#ff0000]Fname)[/color].Activate
        Range("A1").Select
        ActiveSheet.Paste
        Columns("D:N").Copy
        Range("D1").PasteSpecial Paste:=xlPasteValues
 
Hi,

Code:
Fname = Format( Sheets("Master").Range("k1").Text, "dd-mmm")



Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks Skip, however I still get the compile error -invalid qualifier.
I'm using Windows 7, Excel 2010 SP1 MSO.
Yet on my old vista machine with Excel 2007, the process runs without error [ponder]
 
here's what you need to do to verify that the window that you are attempting to activate is EXACTLY that name:
Code:
Windows([highlight]"Weekly data week ending " & Fname[/highlight]).Activate

faq707-4594



Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
.Text property returns text from a cell as per the cell's formatting, so you shouldn't need to reapply a format to it. You would if you were returning the .value property.
 
Try to set error trapping (VBE options) to "break on all errors", check the references (sometimes missing one causes unexpected errors).

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top