最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

excel - VBA - Open a file using a macro without reformatting cells - Stack Overflow

programmeradmin3浏览0评论

I currently have a macro that opens a file and moves data around. Within the file being opened there are numbers in column A that have been formatted as text to avoid excel reformatting them (e.g. '1234123412341234). If I open that file by double clicking on it (i.e. not using the macro) then those cells remain as text and I can see the full numbers. However, if I run the macro the cells always reformat (see screenshot for what I mean).

I've tried so many ways to get the macro to open the file and not reformat the cells, but I am now stuck.

This is the code I normally use:

' pop up to choose file
myFile = Application.GetOpenFilename
' check a file was chosen correctly
If myFile = "False" Then Exit Sub
If TypeName(myFile) = "Boolean" Then Exit Sub
' open the file
Workbooks.Open myFile

Is anyone aware of a way to open the file (it is a CSV) using VBA without this reformatting happening? I need the full numbers to be available for some of the remaining steps in the macro to work with.

Thank you!

发布评论

评论列表(0)

  1. 暂无评论