Solved

open excel file from code

Posted on 2016-08-17
6
53 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
  • 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
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

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

708 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

13 Experts available now in Live!

Get 1:1 Help Now