We help IT Professionals succeed at work.
Get Started

Error with Index, ENVIRON and EXCEL.exe

108 Views
Last Modified: 2018-05-29
dear team,
I am using office 2016.
i have developed a database using office 2016.
after deploying my end users (uses office 2013 ) facing issues with application.
1. on opening database . It is popup with  " searching for referenced file EXCEL.exe ".
2. HERE IS THE CODE FOR YOUR REFERENCE.
********************************************************************************************************************************
Option Compare Database
Private Sub cmdchemicalsearchexport_Click()
 Dim saveloc As String, strWorksheetPath As String, xl As Object, wb As Object
    Dim exportsheet As Object, Header As Variant, OIHeader As Variant
    'Dim db As DAO.Database, ExportRecordSet As DAO.Recordset
Dim db As Database
Set db = CurrentDb
Dim rs As Recordset
    saveloc = Environ("USERPROFILE") & "\Desktop\"
    saveloc = strWorksheetPath & "ChemicalSearchReport.xlsx"
    Set xl = CreateObject("Excel.Application")
    Set wb = xl.Workbooks.Add
    Set exportsheet = wb.Worksheets(1)
    exportsheet.Name = "Chemical Search"
    xl.Application.Visible = True
   Set rs = db.OpenRecordset(Me.RecordSource)
        exportsheet.Cells(1, 1).Value = "Trade Name"
        exportsheet.Cells(2, 1).Value = "Supplier"
        exportsheet.Cells(3, 1).Value = "Category"
        exportsheet.Cells(4, 1).Value = "Physical Appearance"
        exportsheet.Cells(5, 1).Value = "Active Ingredient"
        exportsheet.Cells(6, 1).Value = "Regional Availability"
        exportsheet.Cells(7, 1).Value = "EPA#"
        exportsheet.Cells(8, 1).Value = "Comment"
        exportsheet.Range("A1:A8").Font.Bold = True
    Dim rownum As Long, colnum As Long
    Dim i As Long
    i = 0
    rownum = 1
    colnum = 2
    rs.MoveFirst
    For Index = 1 To rs.Fields.Count
    If rs.Fields(i).Name <> "SDS" And rs.Fields(i).Name <> "CID" Then
        Do While Not rs.EOF
        exportsheet.Cells(rownum, colnum).Value = rs.Fields(i).Value
        rs.MoveNext
        colnum = colnum + 1
        Loop
        rownum = rownum + 1
        colnum = 2
    End If
    i = i + 1
    rs.MoveFirst
    Next
  With exportsheet
  .Cells(1, i).Select
   Set testRange = .Range(.Cells(1, 1), .Cells(i - 2, i + 1))
 End With
  testRange.Borders.LineStyle = xlContinuous
exportsheet.Cells.EntireColumn.AutoFit
    End Sub
********************************************************************************************************************************
ERROR 1 :
POINTING to Environ(saveloc = Environ("USERPROFILE") & "\Desktop\")
Compile error:
Can't find project or library
ERROR 2:
I HAVE COMMENTED i.e 'saveloc = Environ("USERPROFILE") & "\Desktop\"
pointing to  Index ( for your referecne For Index = 1 To rs.Fields.Count)
Can't find project or library
Comment
Watch Question
Analyst Assistant
CERTIFIED EXPERT
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE