Solved

VBA ByRef error

Posted on 2014-10-18
5
150 Views
Last Modified: 2014-10-20
Anyone know why the code below doesn't work?
I have an Excel workbook with a form and a module.
The form contains a button that contains:
Application.Run "startExport"

In the module I have:
Private Sub startExport()
    Dim thePath, theFile As String
   
    thePath = Application.ThisWorkbook.Path
    theFile = Application.ThisWorkbook.Path & "\" & frmProject.txtProject & "Import.csv"
   
    writeProjectLine thePath, theFile
End Sub

The code gives a "ByRef argument type mismatch" error and highlights the variable "thePath" that is shown in bold above.
0
Comment
Question by:classnet
  • 2
  • 2
5 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40389253
What is  frmProject.txtProject? If it is folder than the "\" is needed to get to csv file?

Can you post the  code of the writeProjectLine  sub? Or excel?
0
 

Author Comment

by:classnet
ID: 40391685
I've requested that this question be deleted for the following reason:

Found a workaround
0
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40391043
You may have found a workaround but note that when you do

Dim thePath, theFile As String

that only theFile is a string. thePath remains as a Variant and that may be your problem.
0
 

Author Closing Comment

by:classnet
ID: 40391686
Not sure if this "Award" will take given the pending delete status.
Not only did your post help with this situation, but it helped me avoid potential issues as well!
I have changed my "slimy hack" workaround.

Thank you!
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40392051
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
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 Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

895 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

11 Experts available now in Live!

Get 1:1 Help Now