Solved

open excel file from code

Posted on 2016-08-17
6
88 Views
Last Modified: 2016-08-17
excel 2010 vba

I have a command button on a form to open excel files.
I need it revamped to: Only open a specific excel file name(provided in code) from a specific folder on a server

MyFile.xls
or
MyFile.xlsx



10.xx.xxx.xx\c:\mydata\folderTemp


Sub XET_OpenAllXfilesInFolder()
    fldr = GetFolder(ActiveWorkbook.Path)
    xfile = Dir(fldr & "\*.xlsx")
    Do While xfile <> ""
        Workbooks.Open Filename:=fldr & "\" & xfile
    Loop
End Sub
0
Comment
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
Martin Andrews earned 500 total points
ID: 41760001
You simply need to use the open function with the hardcoded values for fpath and fname

Dim owb As Workbook
owb = Workbooks.Open(fpath & "\" & fname)

Open in new window

0
 
LVL 3

Author Comment

by:fordraiders
ID: 41760018
getting object variable with block varaiable not set.
0
 
LVL 3

Author Comment

by:fordraiders
ID: 41760035
Dim sPath As String
Dim sFile As String
Dim sDir As String
Dim oLB As Workbook
Dim i1 As Long
Dim iMax As Long
 
sPath = "C:\Program Files\prise\iuom\"
sDir = FileSystem.Dir(sPath & "Version_iUom_Enterprise.xls", vbNormal)
 
    Set oLB = Workbooks.Open(sPath & sDir)


This working with no errors but i do not see the workbook.
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 3

Author Comment

by:fordraiders
ID: 41760044
Workbooks.Application.Visible = true
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 41760045
Thanks
0
 
LVL 2

Expert Comment

by:Martin Andrews
ID: 41760050
If your original code was working ng, you can simply use that, the point is that you simply set it manually in your code rather than letting the user select it:

Dim own as Workbook
Workbooks.Open Filename:=fpath & "\" & fname
Set owb = ActiveWorkbook

Open in new window

0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

635 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