Solved

VBA ByRef error

Posted on 2014-10-18
5
153 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

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…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

830 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