Solved

open excel file from code

Posted on 2016-08-17
6
62 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

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;…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

919 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

12 Experts available now in Live!

Get 1:1 Help Now